The code I have is setup to redirect pages in a CMS. Here's the code I am using:
- Code: Select all
RewriteRule (^.*)(BBCode|Downloads|Members|Messages|News|Privacy|Search|Sections|Static)-?([0-9A-Za-z]*)-?([0-9A-Za-z]*)-?([0-9A-Za-z]*).html index.php?mod=$2&op=$3&id=$4&start=$5&%{QUERY_STRING} [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ (.*)/index\.php\?mod=(BBCode|Downloads|Members|Messages|News|Privacy|Search|Sections|Static)&op=([^&]+)&id=([^&]+)&start=([^&]+)&?(.*)\ HTTP/
RewriteRule ^index\.php$ %1/%2-%3-%4-%5.html?%6 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ (.*)/index\.php\?mod=(BBCode|Downloads|Members|Messages|News|Privacy|Search|Sections|Static)&op=([^&]+)&id=([^&]+)&?(.*)\ HTTP/
RewriteRule ^index\.php$ %1/%2-%3-%4.html?%5 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ (.*)/index\.php\?mod=(BBCode|Downloads|Members|Messages|News|Privacy|Search|Sections|Static)&op=([^&]+)&?(.*)\ HTTP/
RewriteRule ^index\.php$ %1/%2-%3.html?%4 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ (.*)/index\.php\?mod=(BBCode|Downloads|Members|Messages|News|Privacy|Search|Sections|Static)&?(.*)\ HTTP/
RewriteRule ^index\.php$ %1/%2.html?%3 [R=301,L]
The first line is a URL shortner so that a page such as Sections-read-1.html will display the content for index.php?mod=Sections&op=read&id=1.
When a module (mod= and then the string of OR statements) is added or removed from the CMS, a script modifies the code above within the htacces file. I would like to make it as easy as possible to modify. Therefore, the next 4 sets of lines is what I would really like to condense. Each set is a condition for a slightly shorter url. In example:
- index.php?mod=Sections&op=read&id=1&start=20 redirects to Sections-read-1-20.html
- index.php?mod=Sections&op=read&id=1 redirects to Sections-read-1.html
- index.php?mod=Sections&op=read redirects to Sections-read.html
- index.php?mod=Sections redirects to Sections.html
- Can I condense these sets of conditions into a simpler else-if statement?
- Can I define a custom variable at the start of the .htaccess file that represents the following string?
BBCode|Downloads|Members|Messages|News|Privacy|Search|Sections|Static