i have a trivial question about htaccess rewrite condition.
The think i want to do in my htaccess is:
When someone accesses my project from a url different from "example.com" to be redirected to a specific controller, for example app_user.php
I need the syntacs for this condition redirect.
Thanks for your time
Try this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/app_user.php
RewriteRule ^ /app_user.php [L]
Related
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 .
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]
If want to redirect all non-www requests to my site to the www version. All I need to do is add the following code to my .htaccess file.
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteCond %{REQUEST_URI} !^/subfolder
RewriteRule .* http://www.mydomain.com%{REQUEST_URI} [R=301,L]
The problem is that when I write for example mydomain.com/products-1 (hidden URL for mydomain.com/products?category=1), all parameters become visible, even though they are specified on the .htaccess file, and I get an output url (after the redirect) of www.mydomain.com/products-1?category=1
How can I fix this? Is there any kind of problems with the .htaccess code above?
Try Changing your RewriteRule:
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{REQUEST_URI} !^/subfolder
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
I prefer this because it will catch all *.domain.com. If that is not what you want, then use your original HTTP_HOST rule.
If my logic is working this morning, this rule should rewrite any requests that do not match:
www.example.com
and do not contain
/subfolder
to
www.domain.com/URI
OK I'm new with the issue of URL rewriting and redirecting. I've search up and down on Google & Stackoverflow for an answer that would work and nothing seems to work!!
What i'm trying to accomplish is...
Take this link: mysite.com/research/index.php?quote=goog
Then convert it and redirect it to this: mysite.com/research/goog
Does it matter that the "goog" at the end of the URL string is grabbed from a form placed in the url? here is the code used to grab the "goog" <?php echo $_POST['quote'];?>
Below is the only snippet code that I have on my htaccess file and it won't work! Am I doing it wrong? Is there something missing from my code? I have my code place on the root directory (mysite.com) should i have it in the "research" folder? (mysite.com/research/)
RewriteEngine On
RewriteRule ^quote/([^/]*)$ /research/index.php?quote=$1 [L]
Is it possible my host / server doesn't accept .htaccess files? should I do it in a web.config file? If so how would I convert the above code to a working web.config file?
These are the rules you will need in your /research/.htaccess file:
RewriteEngine On
RewriteBase /research/
RewriteCond %{THE_REQUEST} /index\.php\?quote=([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?quote=$1 [L,QSA,NC]
Access it in your index.php using:
$quote = $_GET['quote'];`
This should work for you:
RewriteEngine On
RewriteCond %{QUERY_STRING} "quote=([^&]+)"
RewriteRule ^/research/index.php /research/%1? [R,L]
The query string is a separate part of the request to the URL so you need to check that explicitly. By using the RewriteCond, you can say if the 'quote' parameter exists, you'll capture it's value (by getting all characters that follow it that are not '&'). This populates the %1 variable which you can use in the rewrite itself.
I have a page like
index.php?username=thurein
i need to get with subdomain like
thurein.mydomain.com
how could i get it?
I have done like ..
RewriteEngine on
RewriteCond %{HTTP_HOST} !^mydomain.com [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([^.]+).mydomain.com [NC]
RewriteRule ^$ /index.php?username=%2 [QSA]
But I couldn't pass other variables.
something like ...
thurein.mydomain.com/photos/1
what I want is that url re write to ..
index.php?username=thurein&page=photos&id=1
Thanks
If you can help me .. I do really appropriate for it.
i do this on my htaccess and it works
RewriteEngine on
RewriteCond %{HTTP_HOST} !^mydomain.com [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([^.]+).mydomain.com [NC]
RewriteRule ^([a-z0-9-]+)/$ /subdomain.php?subdomain=%2&menu=$1 [QSA]
for index.php?username=thurein&page=photos&id=1
RewriteRule ^([a-z0-9-]+)/([0-9]+)/$ /subdomain.php?subdomain=%2&page=$1&id=1 [QSA]
hope this solve your problem.
you can redirect all subdomains to main domain for example on index.php, in the script you can parse the url and assign $_GET['username'] = $parsedSubDomain; and the script will do everything like index.php?username=thurein.
I hope it is clear.
P.S you can do the redirection using cPanel if your hosting supports it, or you need to change httpd config.