简体   繁体   中英

url rewriting using .htaccess for unwanted words removal

I need to rewrite url where the url is:

http://www.domainname.co.uk/blog/gallery/gallery2  --> URL1

which need to be

http://www.domainname.co.uk/gallery/gallery2   ---> URL2

where http://www.domainname.co.uk/blog is a directory with wordpress installed. Now when i enter URL2 it should show the content of URL1. Is it possible? I just need to remove the word blog.

-----------my .htaccess---------

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

RewriteRule ^(gallery/.+)$ /blog/$1 [L,NC]
</IfModule>

Edited :
You can do use the rewrite rule as follows if you are using index.php in root folder where htaccess resides.

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

    RewriteRule ^(gallery/.+)$ /blog/$1 [L,NC]
    RewriteRule ^gallery$ http://www.domainname.co.uk/blog/gallery/1$ [L,P]

    RewriteRule . /index.php [L]

</IfModule>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM