Help requested - Mod rewrite

Started on the old forum in October 2017 · view the original in the archive · old links redirect here

#htaccess #modrewrite

2 replies · 64 views · started 9 years ago · 5 min read

2 participants
morse Senior · 364 posts #1

I have the following code in my .htaccess

Options +FollowSymLinks
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://sitename.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www.sitename.com$ [NC]
RewriteRule ^(.*)$ http://sitename.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^sitename.org$ [OR]
RewriteCond %{HTTP_HOST} ^www.sitename.org$
RewriteRule (.*)$ http://sitename.com/$1 [R=301,L]
RewriteRule ^forum/topiclists/([^/]*)\.php$ /forum/topiclists.php?page=$1 [L]
RewriteRule ^bloglists/([^/]*)\.php$ /bloglists.php?page=$1 [L]
RewriteRule ^forum/cat([^/]*)/([^/]*)\.php$ /forum/forum-category.php?cid=$1&name=$2 [L]
RewriteRule ^forum/subcat([^/]*)/([^/]*)\.php$ /forum/mobile-forum.php?fid=$1&name=$2 [L]
RewriteRule ^forum/subcat([^/]*)/([^/]*)/([^/]*)\.php$ /forum/mobile-forum.php?fid=$1&name=$2&page=$3 [L]
RewriteRule ^forum/topic([^/]*)/([^/]*)\.php$ /forum/mobile-forum-topic.php?tid=$1&name=$2 [L]
RewriteRule ^forum/topic([^/]*)/([^/]*)/([^/]*)\.php$ /forum/mobile-forum-topic.php?tid=$1&name=$2&page=$3 [L]
RewriteRule ^forum/topic([^/]*)/([^/]*)/go/([^/]*)\.php$ /forum/mobile-forum-topic.php?tid=$1&name=$2&go=$3 [L]
RewriteRule ^mobileblog/([^_]*)_([^_]*)\.php$ /mobile-blogsx.php?note=$1&nameit=$2 [L]
RewriteRule ^mobile-blogs/([^/]*)\.php$ /mobile-blogs.php?page=$1 [L]
RewriteRule ^forum/index\.php$ http://sitename.com/forum/ [R=301,L]
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
AddType audio/x-midi .mid
AddType audio/mpeg3 .mp3
AddType image/gif .gif .GIF
AddType image/jpeg .jpeg .jpg .jpe .JPG
AddType text/x-vcard .vcf
AddType video/x-msvideo .avi .AVI .xvid
AddType video/3gpp .3gp .3GP
AddType video/mp4 .mp4
AddType audio/aac .m4r .M4R
AddType video/vnd.mpegurl .m4u .mxu
AddType text/vnd.sun.j2me.app-descriptor .jad .JAD
AddType application/vnd.android.package-archive .apk .APK
AddType application/vnd.symbian.install .sis .SIS
AddType x-epoc/x-sisx-app .sisx .SISX
AddType application/java-archive .jar .JAR
AddType application/x-zip-compressed .zip .ZIP
AddType application/x-rar-compressed .rar .RAR
AddType application/txt .vbm
AddType application/octet-stream .ipa
AddType video/quicktime .mov
AddType video/mpeg .mpg .mpeg
AddType application/vnd.rn-realmedia-vbr .rmvb
AddType video/x-ms-wmv .wmv
AddType video/divx .divx
AddType application/vnd.rn-realmedia .rm
AddType application/octet-stream .ipd .alx .rem .rfi .app
AddType text/plain .txt .cod
AddType image/png .png
AddType text/xml .xml
AddType application/rss+xml .rss
AddType application/pdf .pdf
AddType application/vnd.openxmlformats .docx
AddType application/msword .doc
AddType application/x-ms-dos-executable .exe
AddType application/x-font-ttf .ttf
AddType application/octet-stream .ttc
AddType application/octet-stream .fon
<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 hour"
  ExpiresByType text/html "access plus 15 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
</ifModule>
<IfModule mod_deflate.c>
<FilesMatch "\.(js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
<FilesMatch "\.(ico|pdf|flv)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>
<FilesMatch "\.(xml|css|js)$">
Header set Cache-Control "max-age=29030400, proxy-revalidate"
</FilesMatch>
<FilesMatch "\.(html|txt|htm|php)$">
Header set Cache-Control "max-age=60, private, proxy-mustcheck"
</FilesMatch>

My webhost has asked me to add the following snippet for automatic https redirects

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

When I Use the below code, it results into my webdirectory names insomniac being pushed in the url redirects

Options +FollowSymLinks
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://sitename.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www.sitename.com$ [NC]
RewriteRule ^(.*)$ http://sitename.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^sitename.org$ [OR]
RewriteCond %{HTTP_HOST} ^www.sitename.org$
RewriteRule (.*)$ http://sitename.com/$1 [R=301,L]
RewriteRule ^forum/topiclists/([^/]*)\.php$ /forum/topiclists.php?page=$1 [L]
RewriteRule ^bloglists/([^/]*)\.php$ /bloglists.php?page=$1 [L]
RewriteRule ^forum/cat([^/]*)/([^/]*)\.php$ /forum/forum-category.php?cid=$1&name=$2 [L]
RewriteRule ^forum/subcat([^/]*)/([^/]*)\.php$ /forum/mobile-forum.php?fid=$1&name=$2 [L]
RewriteRule ^forum/subcat([^/]*)/([^/]*)/([^/]*)\.php$ /forum/mobile-forum.php?fid=$1&name=$2&page=$3 [L]
RewriteRule ^forum/topic([^/]*)/([^/]*)\.php$ /forum/mobile-forum-topic.php?tid=$1&name=$2 [L]
RewriteRule ^forum/topic([^/]*)/([^/]*)/([^/]*)\.php$ /forum/mobile-forum-topic.php?tid=$1&name=$2&page=$3 [L]
RewriteRule ^forum/topic([^/]*)/([^/]*)/go/([^/]*)\.php$ /forum/mobile-forum-topic.php?tid=$1&name=$2&go=$3 [L]
RewriteRule ^mobileblog/([^_]*)_([^_]*)\.php$ /mobile-blogsx.php?note=$1&nameit=$2 [L]
RewriteRule ^mobile-blogs/([^/]*)\.php$ /mobile-blogs.php?page=$1 [L]
RewriteRule ^forum/index\.php$ http://sitename.com/forum/ [R=301,L]
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
AddType audio/x-midi .mid
AddType audio/mpeg3 .mp3
AddType image/gif .gif .GIF
AddType image/jpeg .jpeg .jpg .jpe .JPG
AddType text/x-vcard .vcf
AddType video/x-msvideo .avi .AVI .xvid
AddType video/3gpp .3gp .3GP
AddType video/mp4 .mp4
AddType audio/aac .m4r .M4R
AddType video/vnd.mpegurl .m4u .mxu
AddType text/vnd.sun.j2me.app-descriptor .jad .JAD
AddType application/vnd.android.package-archive .apk .APK
AddType application/vnd.symbian.install .sis .SIS
AddType x-epoc/x-sisx-app .sisx .SISX
AddType application/java-archive .jar .JAR
AddType application/x-zip-compressed .zip .ZIP
AddType application/x-rar-compressed .rar .RAR
AddType application/txt .vbm
AddType application/octet-stream .ipa
AddType video/quicktime .mov
AddType video/mpeg .mpg .mpeg
AddType application/vnd.rn-realmedia-vbr .rmvb
AddType video/x-ms-wmv .wmv
AddType video/divx .divx
AddType application/vnd.rn-realmedia .rm
AddType application/octet-stream .ipd .alx .rem .rfi .app
AddType text/plain .txt .cod
AddType image/png .png
AddType text/xml .xml
AddType application/rss+xml .rss
AddType application/pdf .pdf
AddType application/vnd.openxmlformats .docx
AddType application/msword .doc
AddType application/x-ms-dos-executable .exe
AddType application/x-font-ttf .ttf
AddType application/octet-stream .ttc
AddType application/octet-stream .fon
<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 hour"
  ExpiresByType text/html "access plus 15 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
</ifModule>
<IfModule mod_deflate.c>
<FilesMatch "\.(js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
<FilesMatch "\.(ico|pdf|flv)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>
<FilesMatch "\.(xml|css|js)$">
Header set Cache-Control "max-age=29030400, proxy-revalidate"
</FilesMatch>
<FilesMatch "\.(html|txt|htm|php)$">
Header set Cache-Control "max-age=60, private, proxy-mustcheck"
</FilesMatch>

Kindly review the code and let me know what I should do to avoid insomniacs being pushed inside the url.

tinyurl.com/earnbymobile Easy earning for Indians

Alternative mobile advertising network .. Minimum 100 USD pay / NET15 pay cycle, Good Brand, Best targeting for Android goo.gl/6vub3

GumSlone Administrator Principal · 1,690 posts #2

try this one

Options +FollowSymLinks
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R=301,L] #here you can use sitename.com instead of %{SERVER_NAME}
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ https://%{SERVER_NAME}/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www.sitename.com$ [NC]
RewriteRule ^(.*)$ https://sitename.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^sitename.org$ [OR]
RewriteCond %{HTTP_HOST} ^www.sitename.org$
RewriteRule ^(.*)$ https://sitename.com/$1 [R=301,L]
RewriteRule ^forum/topiclists/([^/]*)\.php$ /forum/topiclists.php?page=$1 [L]
RewriteRule ^bloglists/([^/]*)\.php$ /bloglists.php?page=$1 [L]
RewriteRule ^forum/cat([^/]*)/([^/]*)\.php$ /forum/forum-category.php?cid=$1&name=$2 [L]
RewriteRule ^forum/subcat([^/]*)/([^/]*)\.php$ /forum/mobile-forum.php?fid=$1&name=$2 [L]
RewriteRule ^forum/subcat([^/]*)/([^/]*)/([^/]*)\.php$ /forum/mobile-forum.php?fid=$1&name=$2&page=$3 [L]
RewriteRule ^forum/topic([^/]*)/([^/]*)\.php$ /forum/mobile-forum-topic.php?tid=$1&name=$2 [L]
RewriteRule ^forum/topic([^/]*)/([^/]*)/([^/]*)\.php$ /forum/mobile-forum-topic.php?tid=$1&name=$2&page=$3 [L]
RewriteRule ^forum/topic([^/]*)/([^/]*)/go/([^/]*)\.php$ /forum/mobile-forum-topic.php?tid=$1&name=$2&go=$3 [L]
RewriteRule ^mobileblog/([^_]*)_([^_]*)\.php$ /mobile-blogsx.php?note=$1&nameit=$2 [L]
RewriteRule ^mobile-blogs/([^/]*)\.php$ /mobile-blogs.php?page=$1 [L]
RewriteRule ^forum/index\.php$ https://sitename.com/forum/ [R=301,L]
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
AddType audio/x-midi .mid
AddType audio/mpeg3 .mp3
AddType image/gif .gif .GIF
AddType image/jpeg .jpeg .jpg .jpe .JPG
AddType text/x-vcard .vcf
AddType video/x-msvideo .avi .AVI .xvid
AddType video/3gpp .3gp .3GP
AddType video/mp4 .mp4
AddType audio/aac .m4r .M4R
AddType video/vnd.mpegurl .m4u .mxu
AddType text/vnd.sun.j2me.app-descriptor .jad .JAD
AddType application/vnd.android.package-archive .apk .APK
AddType application/vnd.symbian.install .sis .SIS
AddType x-epoc/x-sisx-app .sisx .SISX
AddType application/java-archive .jar .JAR
AddType application/x-zip-compressed .zip .ZIP
AddType application/x-rar-compressed .rar .RAR
AddType application/txt .vbm
AddType application/octet-stream .ipa
AddType video/quicktime .mov
AddType video/mpeg .mpg .mpeg
AddType application/vnd.rn-realmedia-vbr .rmvb
AddType video/x-ms-wmv .wmv
AddType video/divx .divx
AddType application/vnd.rn-realmedia .rm
AddType application/octet-stream .ipd .alx .rem .rfi .app
AddType text/plain .txt .cod
AddType image/png .png
AddType text/xml .xml
AddType application/rss+xml .rss
AddType application/pdf .pdf
AddType application/vnd.openxmlformats .docx
AddType application/msword .doc
AddType application/x-ms-dos-executable .exe
AddType application/x-font-ttf .ttf
AddType application/octet-stream .ttc
AddType application/octet-stream .fon
<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 hour"
  ExpiresByType text/html "access plus 15 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
</ifModule>
<IfModule mod_deflate.c>
<FilesMatch "\.(js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
<FilesMatch "\.(ico|pdf|flv)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>
<FilesMatch "\.(xml|css|js)$">
Header set Cache-Control "max-age=29030400, proxy-revalidate"
</FilesMatch>
<FilesMatch "\.(html|txt|htm|php)$">
Header set Cache-Control "max-age=60, private, proxy-mustcheck"
</FilesMatch>

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

morse Senior · 364 posts #3

Thank you! It worked absolutely fine!

tinyurl.com/earnbymobile Easy earning for Indians

Alternative mobile advertising network .. Minimum 100 USD pay / NET15 pay cycle, Good Brand, Best targeting for Android goo.gl/6vub3

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close