2

What I'm asking for is simply rewriting any URL-given sub-directiories to a PHP URL parameter for nicer looking, user friendly URL.

I know that this is possible using the Apache Rewrite Engine and associated parameters. The problem on my end is that I do not want to rewrite i.e

mydomain.com/parameter ----------->
mydomain.com/index.php?id=parameter 

But rewriting

mydomain.com/subdirectory/parameter ----------->
mydomain.com/subdirectory/index.php?id=parameter

In my root folder I have an .htaccess file for 404 errors and such, redirecting non-existant pages to the main one. During the tests I've done I have deactivated these thinking that they could overwrite the other .htaccess file. I tried...

RewriteEngine On
RewriteRule ^directory/([^/\.]+)/?$ index.php?id=$1 [L]

...and other snippets similar to that one.

The .htaccess file containing this code was placed in the root/directory folder. What I wanted to achieve with that was to redirect root/directory/string to root/directory/index.php?id=string.

Since my knowledge of .htaccess and rewriting is obviously limited, I need answers to two questions.

  1. Will a 404 rewriter in the root folder overwrite any other rewriter in a subdirectory?

  2. How do I achieve what I'm after? (much like how url-shorteners work - bit.ly/shortened) from a subdirectory?

4

1 回答 1

3

此规则应该在您的DOCUMENT_ROOT/.htaccess文件中适用于您:

RewriteEngine On
RewriteRule ^(directory)/([^/.]+)/?$ /$1/index.php?id=$2 [L,NC,QSA]

确保没有其他.htaccess文件在directory.

于 2013-10-26T09:21:09.037 回答