htaccess forward slash before domain error /www - .htaccess

My site URL structure is showing in search results as "/www.domain.com" (with a forward slash before www)
I believe the problem is with the htaccess file. Does anyone know a fix?
htaccess code is below. Many thanks.
RewriteEngine On
RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
RewriteRule ^(.*)\.html$ %2$1.php [QSA,L,R=301]
RewriteCond %{HTTP_HOST} ^kentuckycartitleloans.com
RewriteRule (.*) http://www.kentuckycartitleloans.com%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
RewriteRule ^.*about.php$ %2contact.php [QSA,L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
RewriteRule ^.*online-application.php$ %2apply.php [QSA,L,R=301]

Related

website proper redirecting via .htaccess

I searched about .htaccess redirecting address after first symbol / but I can't get it working.
.htaccess file is like this one:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*)$ /index.php?route=/$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^OldDomain [NC]
RewriteRule ^blog/(.*)$ NewDomain/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.OldDomain [NC]
RewriteRule ^blog/(.*)$ http://www.NewDomain/$1 [R=301,L]
When I test it with the domain
www.OldDomain.com/catalog
its redirects to
www.NewDomain.eucatalog
which does not have the slash symbol "/".
How can I make the redirect keep the slash symbol?
This may be unrelated, but you need your redirect rules (the last 2) to come before your routing rule. It's possible your router (index.php) is redirecting incorrectly:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^OldDomain [NC]
RewriteRule ^blog/(.*)$ NewDomain/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.OldDomain [NC]
RewriteRule ^blog/(.*)$ http://www.NewDomain/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*)$ /index.php?route=/$1 [L,QSA]

remove index.php from url only for the client

I know there are some questions like this out there but the solutions are not helpful for me.
I´m using htaccess to redirect to the index.php if the request file isn´t defined (code above).
I´d like to add a code-line that if the user requests for example:
http://www.example.com/test/index.php
he will redirect to
http://www.example.com/test/
but internal it will redirect to the index.php.
Is there a way to extend my code so that it works like I want it to?
# Add Slash
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
# Redirect to index.php if the following sites were not match
RewriteBase /
RewriteCond %{REQUEST_URI} \.(php|sql|tgz|gz|txt|ttf|TTF|log|txt|ini|html|xml|xhtml|htm)$
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteCond %{REQUEST_URI} !^/phpinfo.php$
RewriteCond %{REQUEST_URI} !^/out.php$
RewriteCond %{REQUEST_URI} !^/sitemap[^0-9]*\.xml$
RewriteCond %{REQUEST_URI} !^/robots.txt$
RewriteRule ^(.*)$ /index.php?dir=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ /index.php?dir=$1 [QSA,L]
Complete code:
DirectoryIndex index.php index.html
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# Take off index.php
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]
RewriteRule ^ http://%{HTTP_HOST}%1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} \.(php|sql|tgz|gz|txt|ttf|TTF|log|txt|ini|html|xml|xhtml|htm)$
RewriteCond %{REQUEST_URI} !^/((index|phpinfo|out)\.php|robots\.txt|sitemap[^0-9]*\.xml)$
RewriteRule ^(.*)$ /index.php?dir=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?dir=$1 [QSA,L]
# Add Slash for non-files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

.htaccess single variable url rewrite

I am trying to redirect http://test.pearlsquirrel.com/explore_all?u=hiphop to http://test.pearlsquirrel.com/explore_all/hiphop using htaccess. However, It keeps redirecting here: http://test.pearlsquirrel.com/explore_all/?u=site_error.php. I have looked all over Stackoverflow for the answer but I just can't seem to find it. I would really appreciate some help in fixing this problem, thanks!
Here is my .htaccess file
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.pearlsquirrel.com$ [NC]
RewriteRule ^(.*)$ http://pearlsquirrel.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+) explore_all?u=$1 [L]
You may try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} [^=]+=([^=]+)
RewriteRule .* /%1? [L]
Will map this:
http://test.pearlsquirrel.com/explore_all?u=hiphop
To this:
http://test.pearlsquirrel.com/explore_all/hiphop
Replace the corresponding code in your .htaccess file with this one.
I have not checked the rules in your .htaccess file.
OPTION
Now, if it is the other way around, which I think it is, and the idea is to map this incoming URL:
http://test.pearlsquirrel.com/explore_all/hiphop
To this resource:
http://test.pearlsquirrel.com/explore_all?u=hiphop
Replace the above rule set with this one:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} .*/([^/]+)/?
RewriteRule .* http://test.pearlsquirrel.com/explore_all?u=%1 [L]

htaccess redirect from subdirectory to subdirectory

I'm trying to set up a local instance of a php site working in a server, in the "/" directory. My local instance will work in my development environment in a "/subdirectory/".
I'm trying to translate .htaccess to adapt to this, but I always get a 404. This is original .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^my-nice-url$ /index.php?p=ugly_url
And these are my tries:
RewriteEngine on
RewriteBase /mylocaldirectory/
# Not in local! RewriteCond %{HTTP_HOST} ^example.com$ [NC]
# Not in local! RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^my-nice-url$ /index.php?p=ugly_url
Also
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)my-nice-url$ /index.php?p=ugly_url
Thank you
If i got you right, you want make a user friendly url, i do it like this:
RewriteRule ^(.*)/(your-nice-url)$ ($1)/$2/ [R=301]
RewriteRule ^(.*)/(your-nice-url)/$ $1/index.php?p=$2 [L]
or
RewriteRule ^(.*)/(your-nice-url)$ ($1)/$2/ [R=301]
RewriteRule ^(.*)/(your-nice-url)/$ $1/index.php?p=what-ever-you-need [L]
Hope it help you.

site loading for invalid URL's and redirection error

currently I am using this htaccess access,but the site still loads for invalid url, it doesn't goto 404.
ex: http://www.couponcoder.in/babyoye.com -->works and main content
http://www.couponcoder.in/babyo ----> invalid url, it displays homepage
and site loads for both slash and without slash, I just want it to redirect non-slash
www.couponcoder.in/babyoye.com/
www.couponcoder.in/babyoye.com
can someone help out with this?
Options +Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([a-z.]+)?couponcoder\.in$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .? http://www.%1couponcoder.in%{REQUEST_URI} [R=301,L]
RewriteRule ^admin$ Admin/index.php?qstr=$1 [L]
RewriteRule ^(.*)/$ index.php?qstr=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?qstr=$1 [L]
I can't read if you want to have the non-slash version or if you want to redirect the non-slash version to the slashed one. I'm assuming you want the former.
...
#remove slash, and redirect
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1 [R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?qstr=$1 [L]

Resources