Reputation: 2036
I want to create a dynamic rule of the .htaccess to redirect the page from:
http://www.mydomain.com/subdir/index.php?id=11&title=my-page-title
to:
http://www.mydomain.com/11/my-page-title
Where: - id is an integer number - title is string
I found on stack overflow a similar example but only with a single $_GET
value and not with .htaccess dynamic to static URL
Upvotes: 1
Views: 885
Reputation: 71384
The way you have worded this is actually wrong. What you want to do is to route incoming requests such as:
http://www.mydomain.com/11/my-page-title
To the script at /subdir/index.php
RewriteEngine On
RewriteRule ^/?(.*)/(.*)$ /subdir/index.php?id=$1$title=$2 [L,QSA]
Note that this particular approach will redirect everything on your server of */*
format. If you need to make exceptions such as for static files or only want certain patterns to redirect, you should be more specific in your question.
Upvotes: 4
Reputation: 47945
Try this here:
RewriteRule /([0-9]+)/([a-z-]+) subdir/index.php?id=$1&title=$2
This rule will look for a number with at least 1 diget and a lower case string which can contain minus signs, this could be a
or just -
too.
Upvotes: 2