I got rewrite rules:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www|static)\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301] //add www before adress
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] //remove .php
RewriteRule ^ %1 [R=301]
RewriteCond %{REQUEST_FILENAME} !-d //remove .php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php
RewriteRule ^portfolio/([0-9]+)([^.]*)$ /portfolio-single.php?id=$1 [L]
But the last one dosent work, i want to have adress like www.mysite.com/portfolio/3-some-name => /portfolio-single.php?id=3
I dont know how to get i work.
(Sorry for my bad english)
Change order of rules:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www|static)\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteRule ^portfolio/([0-9]+) /portfolio-single.php?id=$1 [L,NC,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
Related
my htaccess codes add a slash to the end of all URLs but I just want it to add slashes to files ending with the .php file extension how can I do that?
my htaccess codes :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^\/(.*?)\/$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L,NE]
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]
Could you please try following. Written with shown samples only. Please make sure to clear browser cache before testing your URLs
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} \.php$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/seo$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L,NE]
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]
For removing .php extension form URL with filename containing dashes like
http://www.sitename.com/here-the-filename-with-dashes.php
http://www.sitename.com/filename.php
to
http://www.sitename.com/here-the-filename-with-dashes
http://www.sitename.com/filename
I have tried several number of code already but no use via htaccess file.
Here HTACCESS FILE:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
#RewriteRule ^([a-zA-Z0-9_-\s]+)/$ /$1.php
#RewriteRule ^(.*?)/?$ $1.php
RewriteRule ^(.*)$ $1.php
#RewriteRule ^(.*)$http://www.sitename.ca/?$1.php [L,R=302]
#RewriteRule ^([^\.]+)$ $1.php [NC,L]
#RewriteRule ^([a-z]+)\/?$ $1.php [NC]
#RewriteRule ^([^/]+)/$ $1.php
RewriteCond %{HTTP_HOST} ^sitename.com [NC]
RewriteRule ^(.*)$ http://www.sitename.com/$1 [L,R=301]
RewriteRule ^index.php$ http://www.sitename.com/ [R=301,L]
You are on the right path.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sitename.com$ [NC]
RewriteRule ^ http://www.sitename.com%{REQUEST_URI} [L,R=301]
RewriteRule ^index.php$ http://www.sitename.com/ [R=301,L]
RewriteCond %{THE_REQUEST} ^GET\ /(.+)\.php [NC]
RewriteRule ^ /%1 [QSA,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ /$1.php [L]
I'm trying to redirect any non-existing URL back to its main page.
Below is my .htaccess code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
RewriteRule (.*) http://www.example.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
Add that:
RewriteRule ^([^.]+\.[^/.]{3,4})/.* $1 [R=301,L]
And no need to use more than one RewriteEngine on for all the .htaccess.
My rewrite code is:
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteRule ^products/([a-z0-9_-]+)$ products.php?slug=$1
But, this shows and internal server error for the products/slugname rewrite rule.
I've only used small letter, numbers and dash(-) in my slug id.
Try this :
RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]+)/?$ /$1.php [NC,L]
RewriteRule ^products/([a-z0-9_-]+)$ /products.php?slug=$1 [NC,L]
I have an .htaccess that is working fine, I just need to add the page name before the parameters
Options -MultiViews
RewriteEngine On
RewriteBase /new/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
# PRODUCT PAGE IS WORKING GREAT
# NEWS PAGE I AM TRYING TO SHOW THE PAGE NAME
RewriteCond %{THE_REQUEST} /morenews\?id=([^&\s]+)\s [NC]
RewriteRule . morenews/%1/? [R=301,L]
RewriteRule ^morenews/([^/]+)/$ morenews?id=$1 [L]
# THIS ISLEADING TO INTERNATL SERVER ERROR 500
#http://www.lebmotors.com/new/morenews/12/
# PRODUCT PAGE IS WORKING GREAT
# NEED TO SHOW moreprod before parametsr it is now just website new/1/2/3/4 i ned to make it website/new/moreprod/2/2/3/4
RewriteCond %{THE_REQUEST} /moreprod\?id=([^&\s]+)\s [NC]
RewriteRule . %1/? [R=301,L]
RewriteCond %{THE_REQUEST} /moreprod\?id=([^&\s]+)&topid=([^&\s]+)\s [NC]
RewriteRule . %1/%2/? [R=301,L]
RewriteCond %{THE_REQUEST} /moreprod\?id=([^&\s]+)&topid=([^&\s]+)&catid=([^&\s]+)\s [NC]
RewriteRule . %1/%2/%3/? [R=301,L]
RewriteCond %{THE_REQUEST} /moreprod\?id=([^&\s]+)&topid=([^&\s]+)&catid=([^&\s]+)&cagid=([^&\s]+)\s [NC]
RewriteRule . %1/%2/%3/%4/? [R=301,L]
RewriteRule ^([^/]+)/$ moreprod?id=$1 [L]
RewriteRule ^([^/]+)/([^/]+)/$ moreprod?id=$1&topid=$2 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ moreprod?id=$1&topid=$2&catid=$3 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ moreprod?id=$1&topid=$2&catid=$3&cagid=$4 [L]
I am trying to show pagename before paramters
Resolved, just moved these lines to the bottom of .htaccess
RewriteEngine On
RewriteBase /new/
....
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/? [R=301,L]
.....
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)&topid=([^&\s]+)&catid=([^&\s]+)&cagid=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/%2/%3/%4/? [R=301,L]
RewriteRule ^moreprod/([^/]+)/$ moreprod.php?id=$1 [L]
.....
RewriteRule ^moreprod/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ moreprod.php?id=$1&topid=$2&catid=$3&cagid=$4 [L]
# THIS TO THE BOTTOM
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]