unigg
unigg

Reputation: 464

how to rewrite the url in .htaceess in wordpress for this?

In wordpress, I want http://www.example.com/domain/12345/ redirect to

http://www.example.com/page.php?a=domain&b=12345

The default setting of .htaccess is as follow,

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

I add another statement at end of IfModule but not work

RewriteRule ^http://%{HTTP_HOST}%/(.*)/(.*)/$ page.php?a=$1&b=$2 [L,NC]

Anything wrong? (the .htaccess is located in the root dir of wordpress)

Upvotes: 0

Views: 297

Answers (2)

Jake
Jake

Reputation: 2087

Just to be sure. In Wordpress, you can click on "Permalinks" under "Settings" in the admin and completely control your URLs from there. This will create dynamic rules to manage rewriting.

If this is something you need to do for another reason, adjust your code like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^http://%{HTTP_HOST}%/(.*)/(.*)/$ page.php?a=$1&b=$2 [L,NC]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

If you put the rewriterule there, and your htaccess file is writable by a script, that line will be overwritten if you update permalinks in wp later though.

Upvotes: 1

davidosomething
davidosomething

Reputation: 3437

The [L] implies that this is the last rule that should be processed if the conditions match.

The first rule matches requests for index.php and redirects to there.

The second rule matches requests for anything else that isn't an existing filename or directory (using the two conditions) and then redirects to index.php and stops processing.

Putting your RewriteRule BEFORE the two RewriteCond lines will allow check for a path matching the regex and redirect to page.php. You'll have to modify your regex to keep using the WordPress permalink rewrites though, the /(.)/(.)/ rule is too generic and will match almost anything.

Upvotes: 2

Related Questions