简体   繁体   中英

htaccess rewrite regex issue

My current URL is:

http://www.domain.com/param1/ID

But I need the following URL to show the content of my current URL:

http://www.domain.com/param2/param1/ID-page-name

So when page with this URL is loaded:

http://www.domain.com/param2/param1/ID-page-name

Content of this URL should show up:

http://www.domain.com/param1/ID

Basically stripping out param2 and page-name .

The following code did not work in htaccess file:

RewriteCond %{REQUEST_URI} ^/([^/]*)/param1/([^/]*)
RewriteRule ^/([^/]*)/param1/([^/]*)$ /param1/$2

Please help.

EDIT : Looks like this line RewriteEngine On causes 500 server error. No idea what it could be. ModRewrite is enabled in httpd.conf .

EDIT 2 : My current htaccess file:

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A604800
</IfModule>
<IfModule mod_headers.c>
    <FilesMatch "\.(jpg|jpeg|png|gif|swf|ico)$">
        Header set Cache-Control "max-age=2592000, public"
    </FilesMatch>
</IfModule>

redirect /url1 http://www.domain.com/url2


#RewriteEngine On

When I uncomment the last line RewriteEngine On - the 500 error occurs.

Try:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[^/]+/([^/]+)/([^-]+)- /$1/$2 [L]

This should work:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/param1/([0-9]+)-(.*)$ /param1/$2 [L]

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