We made a mistake in the scope of our dynamic pages on a new site, and have some incorrect pages already spidered in Google.
I need to redirect the following format:
http://www.domain.com/dir/dir/?q=120
To this format:
http://www.domain.com/dir/dir/?p=120
Only difference is the 'q' needs to be a 'p'.
RewriteEngine is on, as I've already consolidated traffic from domain.com to www.domain.com
This is what I have in my root .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^centerline.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteRule ^(/leadership/detail/)\?q=([0-9]+)$ $1?p=$2 [R=301, L]
Try this:
RewriteCond %{QUERY_STRING} q=([0-9]+)$
RewriteRule ^(.*)$ /$1?p=%1 [L,R=301]
You'll need the RewriteCond as apache doesn't allow matching against the querystring in a RewriteRule
EDIT
RewriteCond %{REQUEST_URI} ^/leadership/detail/$
RewriteCond %{QUERY_STRING} q=([0-9]+)$
RewriteRule ^(.*)$ /$1?p=%1 [L,R=301]
Related
I am hosting multiple domains on one hosting account, so I have made folders in the public_html folder for each domain.
e.g. home/username/public_html/examplewebsite.com/
and
home/username/public_html/otherexamplewebsite.com/
I've been trying to figure out the code I need in my htaccess file to redirect visitors to the appropriate subfolder when they type in examplewebsite.com so that they don't see that they're in a subfolder of the main domain. I found this code originally, which was working:
Options -Indexes +SymLinksIfOwnerMatch
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/domainfolder/
RewriteCond %{HTTP_HOST} ^(www\.)?domainname\.
#Rewrite all those to insert /folder
RewriteRule ^(.*)$ /domainfolder/$1 [L]
but I also want to redirect all visitors who type in the naked domain to the www. version. I found this code, but when I use them both in the htaccess file you can see the subfolder name in the url again:
#Only www, no naked domain
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
I don't really understand much of all this code so If any of you gurus could help me figure out a solution I would really appreciate it!
Keep your rules like this in root .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{HTTP_HOST} ^(www\.)?domainname\. [NC]
RewriteRule !^domainfolder/ domainfolder%{REQUEST_URI} [L,NC]
I have a couple of sub-domains in addition to my main domain. Like so: domain.com, about.domain.com and new.domain.com.
All 3 have their own .htaccess file in their individual root folders.
I am trying to do 2 things:
all traffic gets routed to the same URL respectively.
the URL thankyou.php gets rewritten to /thank-you
Both of these work for the main domain, domain.com.
But they do not work for the sub-domains.
Here is what works for domain.com:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index.php$ http://www.domain.com [R=301,L]
RewriteRule ^thank-you/?$ thankyou.php [NC,L]
Appreciate any help with this.
Use this .htaccess for your sub domain:
Options +FollowSymLinks
RewriteEngine on
#RewriteCond %{HTTP_HOST} !^www.
#RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L,NE]
RewriteCond %{THE_REQUEST} \s/+index\.php\s
RewriteRule ^index.php$ / [R=301,L]
RewriteRule ^thank-you/?$ /thankyou.php [NC,L]
Did you try this yet?
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule (about)(/.*|$) $1.domain.com/$2 [R=301,L]
Problem: I just did a major update to my companies website and trying to get some redirects to work. Right now if I have
Redirect 301 folder1/oldFile1.html http://www.mysite.com/newFolder1/newFolder2/newFile.html
and when you got to the new set up, I get this instead with a 404
http://www.mysite.com/newFolder1/newFolder2/newFile.htmloldFile.html
any ideas what is causing this?
Note: this only appears to happen to files that are moving from a 1 folder structure to a 2 folder structure.
RewriteOptions inherit
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^mysite.com [nc]
rewriterule ^(.*)$ http://www.mysite.com/$1 [r=301,nc]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html?\ HTTP/
RewriteRule ^(.*)index\.html?$ http://www.mysite.com/$1 [R=301,L]
Don't mix mod_rewrite rules with mod_alias rules.
Use this instead:
RewriteOptions inherit
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{http_host} ^mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,NC,L]
RewriteCond %{THE_REQUEST} \s/.*index\.html?\ HTTP/
RewriteRule ^(.*)index\.html?$ http://www.mysite.com/$1 [R=301,L]
RewriteRule ^folder1/oldFile1\.html$ /newFolder1/newFolder2/newFile.html? [R=301,L]
I´m trying to redirect an entire folder which is in domain.com/folder/templates1/, to a maintenance .html page, however I´m getting into a redirect loop with the next code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !/folder/templates1$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /mypage.html [R=302,L]
</IfModule>
Can anyone check this and let me know how could I avoid that loop?
Thank you in advance.
Try this rule:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule !^maintenance\.html /maintenance.html [R=302,L]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/folder/templates1 [NC]
RewriteRule . /mypage.html [R=302,L]
</IfModule>
Should do it. It should send any request starting with /folder/templates1 to /mypage.html, with a 302 (temporary redirect) status. What were you trying to do with the image files? Do you want them exempted? That wasn't in your specification, but can be added with one line:
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif)$ [NC]
Of course, you're on a server (Apache?) that recognizes .htaccess, and the mod_rewrite is enabled.
My actual htaccess redirect my complete old site to my new site, I want to redirect all domain but except two file .php (protectetfile1.php and protectedfile2.php).
This is my htaccess
RewriteEngine On
Rewritecond %{http_host} ^olddomain.org [NC]
Rewriterule ^(.*)$ http://newdomain.net/$1 [L,R=301]
Use this rule:
RewriteEngine On
Rewritecond %{http_host} ^olddomain\.org [NC]
RewriteCond %{REQUEST_URI} !/(protectetfile1|protectetfile2)\.php [NC]
Rewriterule ^(.*)$ http://newdomain.net/$1 [L,R=301]