1
votes

hmm I have a problem with my .htaccess, I wanted to rewrite this:

http://domain.com/a/thread-103518.html#103518

to this

http://domain.com/a/103518

In other words... I want to delete the "thread-" and everything after the "." The /a/ must be variable... there are other forums with /bla/ and /code/

Do you have a clue for me? Thank you

My .htaccess right now:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index.php
RewriteRule ^index.php/?(.*) /$1 [L,R=301]

1
Please clarify which URL is the one "coming in from the wild", and which is your desired output of .htaccess. All too often I see requests to "rewrite [dynamic format] URI to [SEO format]", when the desired action is actually the opposite. If thread-103518.html is a real page, and 103518 is SEO format, you want to rewrite the latter to the former.Phil Perry

1 Answers

1
votes

Add this to the .htaccess file in your DOCUMENT_ROOT

RewriteEngine On
RewriteRule ^([^/]+)/thread-(\d+) $1/$2? [DPI,L,R]

Tested in Apache 2.2 and 2.4 :)

This assumes that mod_rewrite is both installed and activated for htaccess files. If you are not sure, to check if mod_rewrite is installed, look at the list of installed modules in the output of phpinfo(); By default, mod_rewrite is not enabled for htaccess files. If you are managing your own server, open httpd.conf and make sure that the webroot directory block contains one of these lines: AllowOverride FileInfo or AllowOverride All