i'm trying to redirect vendor.php?id=8 to a cleaner path
i'm using this :
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^vendor\.php$ /new-location/%1/? [L,R=301]
it seems to redirect to the right path but i'm not getting the page content:
"Object not found! error 404"
vendor.php placed in root
id number = id from mysql table
You need to set a local (internal) redirect, which reaches the PHP script where your logic resides (currently, it is vendor.php:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /vendor\.php\?id=(\d+) [NC]
RewriteRule ^vendor\.php$ /new-location/%1/? [L,R=301]
RewriteRule ^new-location/(\d+)/?$ /vendor.php?id=$1 [L]
Related
When we are hitting the URL domianname/customer/account/login/%2f we are getting plain page instead of 404 Page without Header and footer
we have try with .htacess by adding
RewriteCond %{QUERY_STRING} ^(.*)((%2F)*)
RewriteRule ^(.*)$ %{REQUEST_URI}? [R=301,L]
still showing same result
also we have try
Added
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ (/.*)\.php
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} !^/error\.php
RewriteRule . - [R=404,L,NS]
ErrorDocument 404 /error.php?e=404
is there anything need to be done at server level ? or it can be handle through .htaccess ?
[1]: https://i.stack.imgur.com/qycvk.pngenter code here
Alright so I have done the process of cleaning up my urls and everything is going good I put the following in my htaccess.
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /l/index.php?mp3=$1&img=http://www.dailynewsounds.com/wp-content/uploads/2016/01/tinashe-5535799554a1b-3.jpg&g=R\%26amp\%3BB&p=8\%20hours\%20ago&s=+Energy&a=Tinashe+Ft.+Juicy+J+ [L]
And this works to change my urls but we have our nasty urls directing to the pages.
http://dl.example.com/l/index.php?mp3=oo8aey7qw3n9&img=http://www.example.com/wp-content/uploads/2016/01/stuey-rock-ft-sy-ari-da-kid-569e83c69cf5e.jpeg&g=R%26amp%3BB&p=10%20hours%20ago&s=+Me+And+You&a=Stuey+Rock+Ft.+Sy+Ari+Da+Kid+
How can I make it so that I can check my url to see if it contains index.php and if it does redirect it to the new page?
Try the following rules:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /l/index\.php\?\S*mp3=\S* [NC]
RewriteCond %{QUERY_STRING} \bmp3=([^\s&]+) [NC]
RewriteRule ^ /%1.html? [R=301,L]
If you're using Apache 2.4.x, then replace the L] with L,QSD].
What am trying to do in that code is:
Any visitor click on an href like http://domain.com/article.php?id=44 the .htaccess will transfer him to domain/article/44
then another rewrite rule to to get the content of requested id from the file article.php
RewriteCond %{QUERY_STRING} ^id=([^&]*)
RewriteRule ^article\.php$ http://alarabe.org/article/%1?
RewriteRule ^article/([a-z0-9\-]+)$ /article.php?id=$1 [L]
This rule isn't right and will certainly cause looping. You need to use THE_REQUEST variable that represents original request received by Apache from your browser.
Try this instead:
RewriteCond %{THE_REQUEST} \s/+article\.php\?id=([^\s&]+) [NC]
RewriteRule ^ http://alarabe.org/article/%1? [R=302,L]
RewriteRule ^article/([a-z0-9\-]+)$ /article.php?id=$1 [L]
What am I doing wrong?
I have
http://www.site.com/shop/viewmy/?ASIN=234FhK3
http://www.site.com/shop/viewmy/?ASIN=423ZH3
Trying to convert to
http://www.site.com/shopping/234FhK3/moved
http://www.site.com/shopping/423ZH3/moved
I'm going to change the "moved" part with an internal redirect after I get some info about the product 234FhK3 , a variable that changes.
I have tried
RewriteCond %{QUERY_STRING} ASIN=([^&]+) [NC]
RewriteRule ^[^/]+/(shopping/)/?$ $1.(/moved)? [L,R=301,NC]
I'm not too good with htaccess rewrites.
Try this:
RewriteCond %{QUERY_STRING} ASIN=([^&]+) [NC]
RewriteRule ^shop/viewmy/$ /shopping/%1/moved/? [L,R=301,NC]
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]