.htacces redirection issue with subfolder php - php

I want to redirect this link http://www.usedcarstampa.com/blog/?m=201511
to
http://www.usedcarstampa.com/blog/
I am trying the following in .htaccess file
1) Not working
Redirect /usedcarstampa.com/blog/index.php?m=201511 /index.php
2) Not working
RewriteEngine on
RewriteCond %{QUERY_STRING} (^|&)m=201511(&|$) [NC]
Rewrite-rule ^index.php$ /? [R=301,NC] // not working
note :- main site in core PHP and blog part in word-press
there is also a another ht-access file in blog/ directory. I am also try above code to right there but i not get positive result
please help,thanks in advance

Try this rule as very first rule in your /blog/.htaccess:
RewriteEngine on
RewriteCond %{QUERY_STRING} (^|&)m=201511(&|$) [NC]
RewriteRule ^(index\.php)?$ /? [R=301,L]

Related

Different htaccess directory and subdirectory redirect

I am trying to have clean urls on my site and here is the mapping I'm trying to achieve:
mysite.tld/directory/ is going to > mysite.tld/page.php?q=directory
mysite.tld/tags/directory/ is going to > mysite.tld/tag.php?q=directory
I have made an htaccess file at the root of my site wiht the folling code:
RewriteEngine On
RewriteRule ^([^\/]+)\/?$ pages.php?q=$1 [L,QSA]
RewriteRule ^tags/([^/d]+)/?$ tags.php?q=$1 [L,QSA]
For some reason, the tag redirect works but is then "eaten" by the other rule of redirection. Not sure what to do to prevent second rule from doing this.
Answer is as follow:
RewriteEngine On
RewriteRule ^tags/([^/d]+)\/? /tags.php?q=$1 [L,QSA]
RewriteCond %{REQUEST_URI} !/tags
RewriteRule (.*) pages.php?q=$1 [L,QSA]

How to setup rule in .htacces to remove two sub directories

I have setup .htaccess to rewrite some rules in our system and they are all working fine.
Howevever, i am having trouble with the following rule. Can anyone help with this?
I have the following URL
test.com/admin/page/files/TEMPFILES/file.pdf
I would like this to be redirected if the url contains the following two strings "/admin/page/" AND "TEMPFILES"
i would like this to redirect to the following
test.com/files/TEMPFILES/file.pdf
I have tried the following
RewriteCond %{QUERY_STRING} ^TEMPFILES
RewriteCond %{REQUEST_URI} ^admin/([a-z]+)(/.*) [NC]
RewriteRule ^(/.*)?$ $2 [NC,L,QSA]
Any help will be appreciated.
Following URL
test.com/admin/page/files/TEMPFILES/file.pdf
should redirect to
test.com/files/TEMPFILES/file.pdf
You can use this
RewriteEngine on
RewriteCond %{REQUEST_URI} /admin/page/files/TEMPFILES/(.+)\.pdf$
RewriteRule (.*) /files/TEMPFILES/%1.pdf [L,R=301]
This will redirect /admin/page/files/TEMPFILES/foobar.pdf to /files/TEMPFILES/foobar.pdf .

.htaccess; Too many redirects if two different redirects in .htaccess

I've two types of URLs:
http://www.example.com/?content=contact_form.php
and
http://www.example.com/?content=product.php&id=20
I changed my whole URL system like this:
http://www.example.com/file/contact_form
and
http://www.example.com/product/I-m-the-title/20
Of course I made 301 redirect with .htaccess to tell Google and co. the new URL.
I made it like this:
# Rewrite URLs
RewriteEngine On
RewriteRule ^(ignore)($|/) - [L]
RewriteRule ^file/([^/]*)$ /?content=$1.php [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /?content=$1.php&title=$2&id=$3 [L]
# Redirect old URL to new URL
RewriteCond %{QUERY_STRING} ^content=contact\_form\.php$
RewriteCond %{REQUEST_URI} ^\/$
RewriteRule .* http://www.example.com/file/contact_form? [R=301,L]
RewriteCond %{QUERY_STRING} ^content=product\.php&class=I-m-the-title$
RewriteCond %{REQUEST_URI} ^\/$
RewriteRule .* http://www.example.com/I-m-the-title/Test/20? [R=301,L]
My problem:
It's perfectly working for: http://www.example.com/?content=product.php&id=20
But for http://www.example.com/?content=contact_form.php I'm getting the message that it couldn't get opened because of too much redirect.
Does anybody know what I'm doing wrong? I hope anybody can help me soon because I have to fix it before Google misinterprets it.
Your rule cause an infinite loop because it is rewriting your uri to the same location again and again overriding your internal and external redirects.. To fix the Rewrite loop, add the following at the top of your htaccess
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

.htaccess - Redirect subdomain to folder

This question has probably been asked for over a thousand times, but I've tried so many scripts, and googled so long while finding nothing, I thought, let's just ask.
I simply want m.daltonempire.nl to be redirected to daltonempire.nl/m/ without the user seeing the URL change.
So if m.daltonempire.nl/hello.php is requested, I want the user to keep seeing this URL, while the page given is actually daltonempire.nl/m/hello.php.
Note: I do not want www., so simply http://m.daltonempire.nl
Thanks in advance,
Isaiah v. Hunen
Add this to your .htaccess in your web root / directory
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^m\.daltonempire\.nl$ [NC]
RewriteCond %{REQUEST_URI} !^/m(/|$) [NC]
RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^(.*)$ m/$1 [L]
The %{REQUEST_FILENAME} conditions would let you access /exists.php and not rewrite it to /m/exists.php. Remove those two if you want to rewrite even if that may potentially override existing files and directories.
Try this example:
RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteRule (.+)$ "http://example.com/%1" [L,P]
Any requests http://test.example.com will be mapped to http://example.com/test/...
Try googling dynamic subdomain with php and htaccess to get better search results.
I have set CNAME of my sub domain below:
blog.mydomain.com
to my wordpress that installed in folder /blog/ under root directory.
Formerly I need to use this url to call wordpress:
http://blog.mydomain.com/blog/
which is ugly. I have tried many code to redirect:
http://blog.mydomain.com/
to the folder so I can use it as my wordpress url.
Finally I got .htaccess setting that is work:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.mydomain\.com$
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule (.*) /blog/$1
I have also CNAME other subdomain: http://forum.mydomain.com to mybb installation in folder /forum/mybb/ so the .htaccess need to put [L] on each of RewriteRule code as below.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^forum\.tophyips\.info$
RewriteCond %{REQUEST_URI} !^/forum/mybb/
RewriteRule (.*) /forum/mybb/$1 [L]
RewriteCond %{HTTP_HOST} ^blog\.tophyips\.info$
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule (.*) /blog/$1 [L]
In case you want to use the code please don't forget to set the site url and cookie path in the application config file follow to the setting to make the redirection work properly.

.htaccess Remove PHP get data from URL

Well I'm making profile pages so right now it looks like this
http://example.com/random/?user=Robert
What I want to do is remove ?user= from the URL so the page appears as
http://example.com/random/Robert
Iv'e searched and I can't find anything working for me.
Thanks!
Based on http://statichtml.com/2010/mod-rewrite-baseon-on-query-string.html this should do the trick:
RewriteCond %{QUERY_STRING} ^user=(.*)$ [NC]
RewriteRule ^random$ random/$1 [NC,L,R=301]
The first step is to make all of your links in this form http://example.com/random/Robert, then in the htaccess file in your document root, add:
RewriteEngine On
RewriteRule ^random/(.+)$ /random/?user=$1 [L]
But to handle 301 redirects to your old URLs, you can include this:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /random/\?user=([^\ ]+)
RewriteRule ^random/$ /random/%1 [R=301,L]

Categories