I have return the below htaccess rule for actual URL http://apis.jaspee.com/services/srvcRest.php?rqst=getCMS
RewriteRule ^(.*)$ services/srvcRest.php?rqst=$1 [QSA,NC]
but it works as
http://apis.jaspee.com/services/srvcRest.php?rqst=services/getCMS
because of that the page is redirected to page not found page. $1 fetch the value as services/getCMS but I want the $1 should fetch the value as getCMS only.
If its going in root /.htaccess, try:
RewriteCond %{REQUEST_URI} !^.*/srvcRest\.php$ [NC]
RewriteRule ^services/(.*)$ services/srvcRest.php?rqst=$1 [QSA,NC]
If its going in /services/.htaccess, try:
RewriteCond %{REQUEST_URI} !^.*/srvcRest\.php$ [NC]
RewriteRule ^(.*)$ srvcRest.php?rqst=$1 [QSA,NC]
Related
I have a website, let's say www.example.com but this used to be www.example.nl. All traffic from www.example.nl is now redirected to www.example.com, but as we changed some naming conventions, www.example.nl/seeds now has to redirect to www.example.com/nl/flower-seeds.
The .htaccess file I got contains the following code:
RewriteEngine On
RewriteBase
RewriteCond %{HTTP_HOST} !example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L, R=301]
Redirect 301 /seeds/(.*) example.com/nl/flower-seeds/$1
When I navigate to www.example.nl/seeds/ I end up at www.example.com/seeds/ which ends up in a 404 because I'm missing the /nl/flower- part.
I think Redirect doesn't work properly when the URL is already altered by a RewriteRule. How would you tackle this problem? Any help is appreciated!
You should exclude /seeds/ directory form general rules like this :
RewriteEngine On
RewriteCond %{HTTP_HOST} !example.com$ [NC]
RewriteCond %{REQUEST_URI} !/seeds/(.*)
RewriteRule ^(.*)$ http://www.example.com/$1 [L, R=301]
RewriteCond %{HTTP_HOST} !example.com$ [NC]
RewriteRule ^seeds/(.*)$ http://www.example.com/nl/flower-seeds/$1 [L, R=301]
Note: clear browser cache then test
Also , don't use regex with redirect like what you did :
Redirect 301 /seeds/(.*) example.com/nl/flower-seeds/$1
Here this (.*) has no meaning , you could use either RedirectMatch or RewriteRule
We have a page file here:
ourdomain.com/subfolder1/subfolder2/
But we'd like people to be able to access it by going here:
ourdomain.com/subfolder2/
So we need both a redirect and a rewrite.
Any idea how this can be achieved using htaccess? I've tried a million things and nothing is properly rewriting/redirecting.
What I currently have...
RewriteCond %{REQUEST_URI} ^/subfolder1/subfolder2/?$ [NC,OR]
RewriteRule ^(.*) http://www.ourdomain.com/subfolder2/ [R=301,L]
You can use:
# Redirect from /subfolder1/subfolder2/...
RewriteCond %{THE_REQUEST} \s/+subfolder1/(subfolder2/[^\s?]*) [NC]
RewriteRule ^ %1 [R=301,L]
# Rewrite to /subfolder1/subfolder2/...
RewriteRule ^(subfolder2/.*) /subfolder1/$1 [NC,L]
Another edition to my .htaccess rewriting saga. Everything is now working to a degree but still have some issues.
I have numerous rules to move old urls to new urls, passing variables etc - however there are still a couple of things i need to add, and for the life of me cannot figure out.
I have 3 urls that are directing/rewriting as below.
1 www.mydomain.com/news/dentistry_dental/index.php
2 www.mydomain.com/news/dentistry_dental/index.php?month=April&year=2011
3 www.mydomain.com/news/dentistry_dental/article_detail.php?article=1234&title=some-title
These are redirected & rewritten perfectly to the new urls respectively
1 www.mydomain.com/dental_news/
2 www.mydomain.com/dental_news/April-2011
3 www.mydomain.com/dental_news/1234-some-title
However... Here is the problem #1 The following urls are also redirecting as below
4 www.mydomain.com/news/it_technology/index.php?month=April&year=2011
5 www.mydomain.com/news/it_technology/article_detail.php?article=1234&title=some-title
Which are also directing to the same urls as the dental redirects
4 www.mydomain.com/dental_news/April-2011
5 www.mydomain.com/dental_news/1234-some-title
Which shouldnt be happening. The it_technology news articles have now been removed so i wish to redirect them either to my homepage with a 410 or something similar, whichever is the best option really.
My current .htaccess looks as follows.
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^mydomain.com [nc]
rewriterule ^(.*)$ http://www.mydomain.com/$1 [r=301,nc]
# Rewrite all index.php to root: / ( with perm redirect )
RewriteCond %{REQUEST_URI} !/generator/
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.mydomain.com/$1 [R=301]
RewriteRule ^products/dental-digital-imaging/([^/]*)_([^/]*)$ /products/digital_xray.php?id=$1&product=$2 [L]
RewriteRule ^products/package_deals.php$ http://www.mydomain.com/products/dental-computer-network-bundles [R=301]
RewriteRule ^products/computer_hardware.php$ http://www.mydomain.com/products/dental-computer-solutions [R=301]
RewriteRule ^products/individual_computers.php$ http://www.mydomain.com/products/dental-computer-systems [R=301]
RewriteRule ^products/digital_xray_imaging.php$ http://www.mydomain.com/products/dental-digital-imaging [R=301]
RewriteRule dental_news/$ /news/dentistry_dental/?rewrite [L]
# Rewrite dental news article to neat nice url
# Protect from looping because of previous rules
RewriteCond %{QUERY_STRING} !rewrite
RewriteRule ^dental_news/([0-9]*)-([^/]*)$ news/dentistry_dental/article_detail.php?article=$1&title=$2&rewrite [L]
#Conditional rewrite of old news article path to new one with 301 redirect
RewriteCond %{REQUEST_URI} !^/dental_news/
RewriteCond %{QUERY_STRING} article=([0-9]*)&title=([^&]*)$
RewriteRule (.*) /dental_news/%1-%2? [L,R=301]
RewriteCond %{REQUEST_URI} !^/dental_news/
RewriteCond %{QUERY_STRING} month=([^&]*)&year=([^&]*)$
RewriteRule (.*) /dental_news/%1-%2? [R=301]
# Protect from looping because of previous rules
RewriteCond %{QUERY_STRING} !rewrite
RewriteRule news/dentistry_dental/$ /dental_news/ [R=301]
# Protect from looping because of previous rules
RewriteCond %{QUERY_STRING} !rewrite
RewriteRule ^dental_news/([a-zA-Z]*)-([0-9]*)/?$ news/dentistry_dental/index.php?month=$1&year=$2&rewrite [L]
# Rewrite URL stripping .php Extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
My only other requirement would be to add a trailing slash to the php files served ( that have allready add the .php extension removed with the last rule in my .htaccess.
I have tried numerous ways that i have found via google, but all of them cuase probelms with my other rules.
Hopefully someone can help me finish this off once and for all.
Regards
M
Sure is getting complicated :) Try changing these lines (I think there are 2):
RewriteCond %{REQUEST_URI} !^/dental_news/
to:
RewriteCond %{REQUEST_URI} ^/news/dentistry_dental/
That way its only going to redirect the old dental news URLs to there respective new ones.
Trivially, your problem is the catch-all rules:
#Conditional rewrite of old news article path to new one with 301 redirect
RewriteCond %{REQUEST_URI} !^/dental_news/
RewriteCond %{QUERY_STRING} article=([0-9]*)&title=([^&]*)$
RewriteRule (.*) /dental_news/%1-%2? [L,R=301]
RewriteCond %{REQUEST_URI} !^/dental_news/
RewriteCond %{QUERY_STRING} month=([^&]*)&year=([^&]*)$
RewriteRule (.*) /dental_news/%1-%2? [R=301]
Restrict them to the path you want to rewrite, i.e. replace .* with something more specific, like:
#Conditional rewrite of old news article path to new one with 301 redirect
RewriteCond %{REQUEST_URI} !^/dental_news/
RewriteCond %{QUERY_STRING} article=([0-9]*)&title=([^&]*)$
RewriteRule ^news/dentistry_dental/index.php$ /dental_news/%1-%2? [L,R=301]
RewriteCond %{REQUEST_URI} !^/dental_news/
RewriteCond %{QUERY_STRING} month=([^&]*)&year=([^&]*)$
RewriteRule ^news/dentistry_dental/index.php$ /dental_news/%1-%2? [R=301]
You can do the news/it_technology redirect as a standard redirect.
RewriteRule ^news/it_technology http://www.thepage.com/ [R=301,L]
It might technically be more correct to do a 410, but the 410 code is really optional. You might also want to make it 404, and then have a link from the 404 page to the main page.
I have subdomains: sub1.tld.com, sub2.tld.com and so on. This subdomains contain important info. But I want to prevent opening any other urls, for example: sub1.tld.com/anypage or sub2.tld.com/dir/more/anyurl.html. This urls must be redirected to main domain tld.com: tld.com/anypage or tld.com/dir/more/anyurl.html
So, i have to check 2 things before redirection:
it's any subdomain
it's not subdomain's root page
I created this rules:
RewriteCond %{HTTP_HOST} ^.+\.tld\.com [NC]
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*) http://tld.com/$1 [R=301,L]
This set of rules works as expected (redirects sub1.tld.com/anypage to tld.com/anypage) but also redirects sub1.tld.com to tld.com. Where is the error? 2nd string is wrong?
Try this:
RewriteCond %{HTTP_HOST} ^.+\.tld\.com$ [NC]
RewriteRule ^/(.+)$ http://tld.com/$1 [R=301,L]
Or you can use this string to check if it root:
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ /\ HTTP/
For some unknown reason the most reliable for checking variable was %{THE_REQUEST}, not %{REQUEST_URI}.
%{THE_REQUEST} contains raw browser's query to web-server: for example, GET /anypage.html HTTP/1.1, if you are opening url http://anysite.com/anypage.html.
So, here you are complete working rule-set for .htaccess:
RewriteCond %{HTTP_HOST} ^.+\.tld\.com$
RewriteCond %{THE_REQUEST} ^get\ /(.+)\ http.* [NC]
RewriteRule ^(.+) http://tld.com/$1 [R=301,L]
i would like to shorten
www.site.com/product/info/laptop to www.site.com/laptop
I used
RewriteRule ^(.+)$ /product/info/$1
but i get 500 Internal Server Error
when i try,
RewriteRule ^([a-zA-Z0-9_\s\'~%,:!?()_=&-]+)$ /product/info/$1
it works but i want to support the period as well, so when I include .
RewriteRule ^([a-zA-Z0-9_\s\'~%,:!?()\._=&-]+)$ /product/info/$1
It gives me 500 Internal Server Error
Could you explain what is going on?
Thank you
Try the following:
RewriteCond %{REQUEST_URI} ^/product/info/(.*)$
RewriteRule ^(.*)?$ /%2 [R=301,L]
That will redirect the browser from www.example.com/product/info/laptop to www.example.com/laptop with a "Moved Permanently" header.
If you mean you wish the shorter URL to point to the longer URL internally, then you must avoid circular redirections:
RewriteRule ^product/info/.*$ - [L] # don't redirect again
RewriteRule ^(.*)$ /product/info/$1 [L] # redirect everything else
The first line will stop trying to redirect www.example.com/product/info/laptop to www.example.com/product/info/product/info/laptop, and so-on.
Edit
Based on your comment, it looks like you're also trying to redirect everything except img, phpmyadmin, etc, to index?whatever - You have to rearrange it all a bit now, something like this:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(index\.php|img|phpmyadmin|images|user|wmd|FCKeditor|map|jscalendar|aurigma|xajax_js|css|js|include|floatbox|helper|styles|ajax|robots\.txt|favicon\.ico|product/info/(.*))
RewriteRule ^(.*)$ - [L] # don't redirect these
RewriteRule ^(.*)$ /product/info/$1 # redirect everything else
I'm not 100% on the "product/info/(.*)" part of the first rewrite. If that doesn't work, try this:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(index\.php|img|phpmyadmin|images|user|wmd|FCKeditor|map|jscalendar|aurigma|xajax_js|css|js|include|floatbox|helper|styles|ajax|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ - [L] # don't redirect these
RewriteRule ^product/info/.*$ - [L] # don't redirect again
RewriteRule ^(.*)$ /product/info/$1 [L] # redirect everything else
Edit 2
Final answer based on your comment:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(index\.php|img|phpmyadmin|images|user|wmd|FCKeditor|map|jscalendar|aurigma|xajax_js|css|js|include|floatbox|helper|styles|ajax|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ - [L] # don't redirect these
# pass controllers to index.php
RewriteCond %{REQUEST_URI} ^/(home|browse|calendar|star|member|enter|product)
RewriteRule ^(.*)$ /index.php?$1 [L]
# pass other things than controllers to /index.php?/product/info/$1
RewriteRule ^(.*)$ /index.php?/product/info/$1 [L] # redirect everything else