Alex Pliutau
Alex Pliutau

Reputation: 21957

htaccess mod_rewrite part of url to GET variable

I have some URLs like these:

How can I with help of Apache mod_rewrite open the next pages?

Also, will be this new rewrite rule work with "one entry point rewriting"?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

Thanks.

Upvotes: 3

Views: 2792

Answers (2)

ThinkingMonkey
ThinkingMonkey

Reputation: 12727

To make the new rewrite rule work with "one entry point rewriting", have your rewriteRules like this:

The QSA flag is mandatory as you are adding a new query string.

RewriteEngine On

RewriteRule ^(post)/([\w\d\-]+)/?$ $1/main?title=$2 [QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . index.php [L]

Upvotes: 3

Sergey P. aka azure
Sergey P. aka azure

Reputation: 4722

You can use something like this in your .htaccess:

RewriteRule ^post/(.*)$ post/main?title=$1 [L]

You should keep this rule BEFORE one entry point rewriting rules. If rule will trigger then rewrite rule lookup will be finished (since [L] option specified)

Some modification of paths may be required if you want to use these rules in VirtualHost context

Upvotes: 3

Related Questions