How can I create a SEO friendly URL [closed] - .htaccess

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have my website name as www.example.com but the 'example' is not related to any of my keywords.
But my competitors have. Is there any solution for index page?
All others Page maintains the proper naming_standard but for index page it creates a problem.
Here's my .htaccess code
RewriteCond %{HTTP:Host} ^example\.com$
RewriteRule (.*) http\://www.example.com$1 [NC,R=301,U]
RewriteRule ^/index.cfm$ http\://www.example.com [NC,R=301,U]
RewriteRule ^/main.cfm$ http\://www.example.com [NC,R=301,U]
RewriteRule ^/ww.example.com$ http\://www.example.com [R=301,L]
RewriteCond %{HTTP:Host} ^ww.example\.com$
RewriteRule (.*) http\://www.example.com$1 [NC,R=301,U]

Try this instead:
RewriteRule ^/index.cfm / [NC,R=301,L]
RewriteRule ^/main.cfm / [NC,R=301,L]
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
The first two rules stop people going to index.cfm and main.cfm directly and redirects them to the base URL.
The third condition and fourth rule check the domain is "www.example.com" and if it is anything else, e.g. without the www. or an alias, 301 redirects them to the same page on "www.example.com".

Related

How to redirect index.php to root in htaccess? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Actually i want to make auto redirect when open
from
test.com/login.php
to
test.com/login/
What should i put on my htaccess file.
You'd first redirect to pretty-url if the raw request matches:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /login\.php [NC]
RewriteRule ^login\.php$ /login/ [R=301,L,NC]
Now, you deal with the rewritten url to internally redirect to correct page:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^login/?$ /login.php [NC,L]
Have you tried something?
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^index/?$ index.php [NC,L]
Your rewrite module should be enabled for doing this?

Remove part from the Url using htaccess [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I ve looked into many examples in stackoverflow and couldn't find a working solution for me.
I have a wordpress blog set up in a subdirectory.
The blog sits under www.domain.co.uk/wordpress/
In order for my permalinks to work I did an htaccess rewrite rule which is this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?domain.co.uk$
RewriteRule ^(/)?$ http://domain.co.uk/wordpress [L]
Is there a way to take out the /wordpress part on the URL?
I need it to point there but I want the /wordpress to be removed.
Any ideas?
I have now managed to solve this issue following this guide: http://www.optiniche.com/blog/145/wordpress-tutorial-install-wordpress-in-a-different-directory/
Remove the wordpress from the redirect in your rule (the http://domain.co.uk/ means there's an implicit redirect) and add a specific rule to internally rewrite instead:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.co.uk$ [NC]
RewriteRule ^ http://domain.co.uk/ [L,R=301]
# now silently rewrite to wordpress
RewriteCond %{REQUEST_URI} !^/wordpress
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wordpress/$1 [L]

htaccess rewrite folder [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have a .htaccess that looks like this
RewriteEngine On
RewriteCond %{REQUEST_URI} !static/(.*)\.
RewriteRule ^(.*)$ index.php?controller=$1 [QSA]
It works fine. /static folder request remain intact, while others execute index.php file.
But now I have to add another rule. When a user navigates to /action/something, then /actions/something.php should be executed. But when I add the following line
RewriteRule ^action/(.*)$ actions/$1.php [QSA]
it breaks requests to static folder.
There is no reason, why it should break static, unless you wrote the new rule right after RewriteCond. What you should do however, rewrite to an absolute URL
RewriteEngine On
RewriteCond %{REQUEST_URI} !static/(.*)\.
RewriteRule ^(.*)$ /index.php?controller=$1 [QSA]
RewriteRule ^action/(.*)$ /actions/$1.php
The RewriteCond looks unusual. Unless there is a reason to rewrite static pages without a dot ., you should reduce the RewriteCond to just
RewriteCond %{REQUEST_URI} !static/
Update:
To prevent the infinite rewrites, you must add another exclusion condition
RewriteCond %{REQUEST_URI} !^/index\.php$
and action must be excluded as well
RewriteCond %{REQUEST_URI} !/actions?/
All put together gives
RewriteEngine On
RewriteCond %{REQUEST_URI} !/static/
RewriteCond %{REQUEST_URI} !/actions?/
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^(.*)$ /index.php?controller=$1 [QSA]
RewriteRule ^action/(.*)$ /actions/$1.php

Remove "www." from url with forceful https [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am using the following in my .htaccess file to force https on any user that is visiting my website without https in the url.
However, if the user visits https://www.mysite.co, I want to be able to remove the www from the request.
Please can you tell me what I need to modify in my .htaccess file in order to remove the www from the url while maintaining the forceful https?
Thanks,
Max.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mysite.co/$1 [R,L]
Do it with 2 rewrites.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://mysite.co/$1 [R,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://mysite.co/$1 [R,L]

subdomain redirection in htaccess [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I was wondering if the following scenario is possible using htaccess rules.
I want one subdomain to be redirected to another url.
I have contact the server admin to add the "test" subdomain to "example.com" domain.
The main domain has no other subdomains.
What rule must i put in htaccess to do achieve:
http://test.example.com to be redirected to http://www.something-else.com.
NOTE: www.something-else.com is a complicated url (200 chars length)
EDIT
My full htaccess file now looks like:
Options +FollowSymLinks
RewriteEngine on
RewriteOptions inherit
RewriteBase /
RewriteCond %{HTTP_HOST} ^test.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/redir.php [L]
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
The htaccess file is located to example.com root directory.
I have no physical access to test subdirectory, although i know it exists - ping to that url shows me the IP of example.com
Typing test.example.com to the browser's address bar has no effect. White screen, no redirection, no nothing. If some page exists there, i know not.
For static urls:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test.example.com$ [NC]
RewriteRule ^(.*)$ https://www.somdomain.com/a/folder1/somepage?var=xxx&var2=xxx&var3=xxx&var4=http://another-domain.com/folder1/xxxxx/?&var5=xxx&var6=xxxx [R=301,NC,L]
For Dynamic urls (if the original domain has folders that needs to be moved to the other domain):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test.example.com$ [NC]
RewriteRule ^(.*)$ https://www.somdomain.com%{REQUEST_URI} [R=301,NC,L,QSA]
From your edit:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^test.example.com$ [NC]
RewriteRule ^(.*)$ redir.php [R=301,NC,L]

Resources