I want to have this form of URL : https://domain(:port)/lang/x/y/z/other
With this htaccess file, I can't achieve exactly what I want.
If I enter the URL https://localhost:port/lang/, I lose the port.
If I enter the URL https://localhost:port/lang, i got the URL https://localhost:port/langx/y/z
Please help me!
Options +FollowSymLinks
RewriteEngine On
#LIVE
RewriteBase /
#--------------------------------------
#-- 404 & 500 Redirects
#--------------------------------------
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
#--------------------------------------
#-- Force HTTPS
#--------------------------------------
RewriteCond %{HTTP_HOST} !=localhost$ [NC]
RewriteCond %{SERVER_PORT} !=8088
RewriteCond %{SERVER_PORT} !=8080
RewriteCond %{HTTPS} !=on
#RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^(actions)($|/) - [L]
#--------------------------------------
#-- Add trailing PHP and Params
#--------------------------------------
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ $1.php?param1=$2¶m2=$3¶m3=$4¶m4=$5 [B,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ $1.php?param1=$2¶m2=$3¶m3=$4 [B,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)$ $1.php?param1=$2¶m2=$3 [B,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#check for the existance of a PHP file first or else the 404 won't work
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]+)$ $1.php?param1=$2 [B,QSA,L]
RewriteRule ^(.*)/$ $1 [R=301,L]
Related
I am facing issues regarding my .htaccess. The .htaccess works, but it causes a problem with the admin folder. Would it be possible to exclude that specific folder from this .htaccess? Here is my .htaccess. It is outside the admin folder.
Options -MultiViews
ErrorDocument 404 http://localhost/blo-prt/err.php
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L,QSA]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blo/([^/\.]+)?$ blo-det.php?postlist=$1 [L,QSA]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^category/blo/([^/\.]+)?$ blo-prior.php?bloglist=$1 [L,QSA]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^tep/([^/\.]+)?$ temp-det.php?telist=$1 [L,QSA]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^category/tep/([^/\.]+)?$ temp-of-prior.php?tlist=$1 [L,QSA]
You should add this to your RewriteConds:
# if request is not for the /admin/
RewriteCond %{REQUEST_URI} !^/admin/ [NC]
Personally, I use this code to remove the .php extension:
# enable url rewriting
RewriteEngine On
# remove .php
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]
Also, you should only type RewriteEngineOn just once at the top of the file.
DirectoryIndex /home.php
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^product/([0-9]+) product.php?id=$1&product_name=$2 [L,QSA]
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
ErrorDocument 404 /404.php
ErrorDocument 403 /403.php
I have this .htaccess file when i try this with 1 parameter it works but with 2 it doesnt work and i want to turn this product.php?id=1&p_name=exmpl link into product/1/exmpl with the above code i have to write this product/1/exmpl with my hand
Here is my .htaccess on a Linux system:
ErrorDocument 401 ./error/
ErrorDocument 403 ./error/
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.website.co.uk/$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.website.co.uk/$1 [R=301,L]
Everything works as it should; www is added to non-www requests and a trailing slash is added. However when visiting www.website.com (which is added as a parked domain on cPanel) the user is NOT redirected to www.website.co.uk
If the visit website.com (note no www) then they ARE redirected.
What do I need to add/change in .htaccess?
Have your rules like this:
ErrorDocument 401 ./error/
ErrorDocument 403 ./error/
RewriteEngine on
RewriteBase /
# if not www.website.co.uk then redirect to it
RewriteCond %{HTTP_HOST} !^www\.website\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.website.co.uk/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ http://www.website.co.uk/$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]
I wanted to create an htaccess file to remove the .php extension and change course.php?id=1 to course/1. But that does not seem to work out. Can any one correct my htaccess?(I am quite new to writing htaccess files)
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
# If request is for a file that does actually exist, don't rewrite.
RewriteCond %{REQUEST_FILENAME} !-f
# If request is for a directory that does actually exist, don't rewrite.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/course/(.*)$ /course.php?id=$1 [NC]
Options -Indexes
Keep it this way:
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# add a trailing slash
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.+)$ $1/ [R=301,L]
RewriteRule ^course/([^/]+)/?$ course.php?id=$1 [NC,L,QSA]
RewriteRule ^([^/]+)/$ $1.php [L]
RewriteRule ^([^/]+)/([^/]+)/$ $1/$2.php [L]
I made a minor change in my .htaccess file and I'm now receiving a 500 internal server error. I changed it back to how it was before the error but, the error is still there.
Here is the file:
ErrorDocument 404 /404-error-page.php
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule \.(css|jpe?g|gif|png)$ - [L]
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^dsa-office /(.*)/ dsa_office.php?location=$1
RewriteRule ^([^/\.]+)/?$ /$1.php [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /$1.php?location=$2 [L]
I edit one of the last 3 lines. Any ideas? Thanks
This rule looks suspicious:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^dsa-office /(.*)/ dsa_office.php?location=$1
It has space in the matching patter between ^dsa-office and /(.*)/
Change this rule to:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^dsa-office/(.*?)/?$ dsa_office.php?location=$1 [L,QSA]