Basically I have:
www.myfancysiteicantcodemyself.com/index.html
with a rewrite rule so it becomes
www.myfancysiteicantcodemyself.com
But what I would really like is this:
*www.myfancysiteicantcodemyself.com/index.html
-> www.myfancysiteicantcodemyself.com/some-cool-words-for-indexpage
www.myfancysiteicantcodemyself.com/anotherpageA.html
-> www.myfancysiteicantcodemyself.com/some-cool-words-for-pageA*
etc.…
How do I achieve this please, without moving files and creating a 301 and google evaluating me from scratch?
PS:
atm my htaccess loks like this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www
RewriteRule ^(.*) http://www.example.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html?|php)\ HTTP/
RewriteRule ^index\.(html?|php)$ http://www.example.com/ [R=301,L]
ErrorDocument 404 /404.html
Header unset ETag
FileETag None
ExpiresActive On
ExpiresDefault "access plus 10 years"
AddHandler application/x-httpd-php .html .htm
You need to do a 301, since google will still try to go to /index.html and /anotherpageA.html, and you'll need to 301 redirect to tell search engines that the content has moved.
So, the easiest way to do this is actually rename your files and use a 301. Otherwise, you're going to have to both do a 301 redirect as well as an internal rewrite.
For example:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www
RewriteRule ^(.*) http://www.example.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html?|php)\ HTTP/
RewriteRule ^index\.(html?|php)$ http://www.example.com/some-cool-words-for-indexpage [R=301,L]
RewriteRule ^some-cool-words-for-indexpage$ /index.html [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /anotherpageA.html\ HTTP/
RewriteRule ^ http://www.example.com/some-cool-words-for-pageA [R=301,L]
RewriteRule ^some-cool-words-for-pageA$ /anotherpageA.html [L]
etc...
Related
I'm trying to redirect all the connections to my website from http to https using htaccess and mod_rewrite, I've tried all the possible things and still not working, I get an error like: The page is not redirecting properly
Here goes the htaccess code:
ErrorDocument 404 http://www.example.com/error.php
<IfModule mod_rewrite.c>
Options -Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^([^/]*)\.html$ /index.php?lang=$1 [L]
RewriteRule ^sites/examplesite/([^/]*)\.html$ /index.php?lang=$1 [L]
RewriteRule ^([^/]*)/examplesite/([^/]*)\.html$ /index.php?lang=$1&page=$2 [L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?lang=$1&page=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ /index.php?lang=$1&idCat=$2&page=$3 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)\.html$ /index.php?lang=$1&cat=$2&filter=$3&pa=$4&page=$5 [L]
RewriteRule ^sites/examplesite/([^/]*)/([^/]*)\.html$ /index.php?lang=$1&page=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ /index.php?lang=$1&show=$2&page=$3 [L]
RewriteRule ^sites/examplesite/([^/]*)/([^/]*)/([^/]*)/([^/]*)\.html$ /index.php?lang=$1&itemID=$2&idCat=$3&page=$4 [L]
RewriteRule ^sites/examplesite/([^/]*)//([^/]*)/([^/]*)\.html$ /index.php?lang=$1&idCat=$2&page=$3 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)\.html$ /index.php?lang=$1&idCat=$2&client_id=$3&page=$4 [L]
</IfModule>
<FilesMatch "\.(ttf|otf|eot|woff)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
php_flag display_errors On
Regarding your main issue , from your code , this part i is what you think that will do forcing all http requests to https:
RewriteCond %{HTTPS} on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
and it is clear that you also want to add www for none www , so first , when you want to catch none https request , your should put like this line :
RewriteCond %{HTTPS} off
because it is condition like saying , if request not into https but in your code you only catch https requests themselves and force them again.
Put the following code instead of the above:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.yourwebsite.com/$1 [R=302,L]
Test it and if it's ok change 302 with 301 to get permanent redirection
I have a blog page on my website and .htaccess is as below to convert SEO Friendly URL
RewriteRule ^([^/.]+)/?$ /blogdetail?prmn=$1 [L]
So, my URL becomes http://example.com/title-of-blog and it is working pretty fine and awesome but my client reported today that admin section is not working properly and i checked and found that URL http://example.com/admin is getting converted to http://example.com/admin?prmn=admin because of above rule.
I googled how to exclude admin folder from Rewrite then i got below
RewriteRule ^admin($|/) - [L]
When i use this then when i type http://example.com/admin then m getting error page that i defined in htaccess.
Please help. My Full Htaccess is as below
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^admin($|/) - [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index
RewriteRule ^index\.php$ / [L,R=301]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
# remove .php from URL
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
# restrict .php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /[^\ ]+\.php($|\ )
RewriteRule \.php$ / [F,L]
# remove .html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)\.html$ /$1 [L,R=301]
RewriteRule ^([^/.]+)/?$ /blogdetail?prmn=$1 [L]
ErrorDocument 404 /error-page
ErrorDocument 403 /error-page
ErrorDocument 500 /error-page
I suppose there is an other rule that does something with /admin, but because you are using that second rule it will never reach that rule. Use a condition to exclude anything starting with admin instead. Also please note that the rule would rewrite it to /blogdetail?prmn=admin, so somewhere something is rewritten more.
RewriteCond %{REQUEST_URI} !^/(admin|blogdetail)
RewriteRule ^([^/.]+)/?$ /blogdetail?prmn=$1 [L]
Can sombody help me out with this, im trying to re direct a page using htaccess file but it keeps adding ?c=oldpage on to the end of the new url, example:
http://www.mydomain.co.uk/newpage.html?c=oldpage
i have tried some of the solutions posted here but no luck, here is my .htaccess file:
DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} PHPSESSID=.*$
RewriteRule (.*) http://www.mydomain.co.uk/$1? [R=301,L]
RewriteCond %{HTTP_HOST} ^mydomain.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.co.uk/$1 [R=301,L]
RewriteCond %{THE_REQUEST} /index\.php\ HTTP/
RewriteRule ^index\.php$ / [R=301,L]
RewriteEngine on
RewriteRule ^product/(.*).html$ product.php?p=$1 [L]
RewriteRule ^(.*)\.html$ category.php?c=$1 [L,NC]
Redirect 301 /oldpage.html http://www.mydomain.co.uk/newpage.html
ErrorDocument 404 /404.php
Thanks for any help.
This is mod_alias (the Redirect directive) and mod_rewrite not playing nicely with each other. Because both modules apply their directives on the same URI in the URL-file mapping pipeline, they don't know to ignore each other since neither directive knows what the other module is doing. Since you're targets overlap, both modules are applying their directives on the same URI and you get a mish-mashed result.
You need to stick with mod_rewrite in this case and move the redirect above the internal rewrites:
DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks
RewriteEngine on
# redirects
RewriteCond %{QUERY_STRING} PHPSESSID=.*$
RewriteRule (.*) http://www.mydomain.co.uk/$1? [R=301,L]
RewriteCond %{HTTP_HOST} ^mydomain.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.co.uk/$1 [R=301,L]
RewriteCond %{THE_REQUEST} /index\.php\ HTTP/
RewriteRule ^index\.php$ / [R=301,L]
RewriteRule ^oldpage.html$ http://www.mydomain.co.uk/newpage.html [R=301,L]
# internal rewrites
RewriteRule ^product/(.*).html$ product.php?p=$1 [L]
RewriteRule ^(.*)\.html$ category.php?c=$1 [L,NC]
ErrorDocument 404 /404.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^abc\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.abc\.net$
RewriteRule ^example\.html$ "http\:\/\/abc\.net\/example\/" [R=301,L]
RewriteOptions inherit
to a folder, or:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^abc\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.abc\.net$
RewriteRule ^example\.html$ "http\:\/\/abc\.net\/example\.html$" [R=301,L]
RewriteOptions inherit
Don't know much about it, but it's what i use, hope it helps.
I wan't the server to always redirect my URL's to format as "http://www.domain.com", even if the user write just "domain.com".
I could find some examples of this on the web, but I already have some fixes in .htaccess file and I don't know, where to put what, so it does't clash with the previous code.
Here's my .htaccess file:
RewriteEngine on
RewriteBase /
ErrorDocument 404 /404
RewriteRule ^adminator/?$ adminator/login.php [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2&detail3=$3&detail4=$4 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2&detail3=$3 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2 [QSA,L]
RewriteRule ^([^/\.]+)/?$ index.php?detail1=$1 [QSA,L]
What should I put in, so it does the URL redirect to "www"?
And one last question, is it all I have to do, so search engines don't have problems with the URL's?
I usually do the contrary.
you probably want www.example.com to forward to example.com -- shorter URLs
are sexier.
no-www.org/faq.php?q=class_b
Thanks to HTML5 boilerplate, I usually add :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</IfModule>
If you want to do that in your .htaccess :
RewriteEngine on
RewriteBase /
ErrorDocument 404 /404
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^adminator/?$ adminator/login.php [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2&detail3=$3&detail4=$4 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2&detail3=$3 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2 [QSA,L]
RewriteRule ^([^/\.]+)/?$ index.php?detail1=$1 [QSA,L]
Else, try the inverse RewriteCond and associate RewriteRule
Your [^/\\.] pattern simplifies to [^/.] as the period does NOT need escaping.
So I have a whole series of redirects in place for a bunch of pages I want redirected to their parent directory (e.g. /faq/question1/ -> /faq/), but it's very inflexible, as they're manually generated.
How can I set up a RegEx-fueled RewriteRule for this? I haven't been able to figure it out, and would dearly love some guidance. Here's the whole of my .htaccess, to avoid any conflicts (you can see the individual RewriteRules I have in place right now):
AddDefaultCharset utf-8
AddHandler php5-script .php
DirectoryIndex index.php
ErrorDocument 403 /errors/forbidden.html
ErrorDocument 500 /errors/internalerror.html
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^halftoneproductions.com
RewriteRule (.*) http://www.halftoneproductions.com/$1 [R=301,L]
# FAQ redirects
RewriteRule ^faq/how-much-does-it-cost-to-make-an-albummix-a-songetc /faq/ [R=301,L]
RewriteRule ^faq/im-a-singersongwriter-with-no-band-members-would-you-be-able-to-do-a-full-production-of-my-songs-with-session-musicians /faq/ [R=301,L]
RewriteRule ^faq/do-you-do-postsound-for-film-at-all /faq/ [R=301,L]
RewriteRule ^faq/i-have-a-home-studio-and-just-need-to-record-___-is-that-cool /faq/ [R=301,L]
RewriteRule ^faq/are-you-a-publishing-company /faq/ [R=301,L]
RewriteRule ^faq/do-you-need-any-interns-or-runners /faq/ [R=301,L]
RewriteRule ^faq/can-i-bring-my-own-producerengineer-to-a-session /faq/ [R=301,L]
RewriteRule ^faq/what-types-of-music-do-you-work-on /faq/ [R=301,L]
RewriteRule ^faq/do-you-work-with-languages-other-than-english /faq/ [R=301,L]
RewriteRule ^faq/do-you-guys-make-beats /faq/ [R=301,L]
RewriteRule ^faq/i-have-an-old-tape-reelcasetteminidiscetc-and-would-love-to-transfer-it-to-some-other-form-can-you-help-out /faq/ [R=301,L]
RewriteRule ^faq/i-have-my-own-producerengineeretc-and-just-need-help-working-out-a-budget-for-my-project-and-booking-studio-time-can-you-help-out /faq/ [R=301,L]
# Recent Work redirects
RewriteRule ^recent-work/josh-and-neal /recent-work/ [R=301,L]
RewriteRule ^recent-work/midnights-son /recent-work/ [R=301,L]
RewriteRule ^recent-work/bearkat /recent-work/ [R=301,L]
RewriteRule ^recent-work/madi-diaz /recent-work/ [R=301,L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
If you want to redirect all requests that’s URL paths have /faq/ as prefix, you can use this rule:
RewriteRule ^faq/. /faq/ [R=301,L]
The single . represents an arbitrary character. So every request that’s URL path starts with /faq/ that followed by at least one character is redirected to /faq/.