I have a problem hundreds of 404 errors on my site that are caused by the expressions "URLONCLICK" and "%5C" being somehow inserted at the end of the correct url, and I don't know where it is coming from but I want to just strip it off of the end of the url in the .htaccess file. How do I do that?
i.e.
www.mydomain.com/category/post-title/URLONCLICK
www.mydomain.com/category/post-title/%5C
I want to strip the end off of these urls so they look like:
www.mydomain.com/category/post-title/
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\%5c $ $1 [NC]
RewriteRule ^(.*)\URLONCLICK $ $1 [NC]
This should do. Maybe there is a better way (merging the last two lines).
Related
I have a number of PDFs in a rails application which have been converted into single page applications and I would now like to redirect the URL from:
www.domain.com/public-pdf-path.pdf
to
www.domain.com/reports/new-non-pdf-url
I've tried redirecting in the routes.rb file like such:
get '/pdf-public-file-path.pdf', to: redirect('/reports/new-url-address')
but it does not hit this redirect. Thoughts on how I could redirect a user to a new URL from the public file path where the pdf lives?
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^DOMAINNAME\.pdf$ [NC]
RewriteRule ^(.*)$ http://DOMAIN.com/newpath [R=301,L]
Hope it helps
I had this exact issue. For me, moving/renaming/deleting the PDF I was trying to redirect made it work. I used the same kind of call in routes.rb as the OP.
Currently my url is mysite.com/content using:
RewriteRule ^page.php/([A-Za-z0-9]+)/?$ page.php?a=b&content=$1 [L]
I'd like to have my url be mysite.com/content/page where both content and page are variables. I thought something like this could work, but obvious it is wrong:
RewriteRule ^page.php/([A-Za-z0-9]+)/?$/([A-Za-z0-9]+)/?$ page.php?a=b&content=$1&page=$2 [L]
What would be the best way to accomplish this?
RewriteRule ^page.php/([A-Za-z0-9]+)/([A-Za-z0-9]+)/?$ page.php?a=b&content=$1&page=$2 [L]
Try this and let me know if this is what you are trying to do.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^?(.*) productfilter.php?category=$1 [NC,L]
This rewrite is returning :
category=productfilter.php
can someone point out what I am doing wrong here
In all likelihood, the issue is that the rewritten URL is getting re-rewritten. Rewrite directives, at least in .htaccess context, get re-executed after a URL rewrite. I think what you are trying to accomplish can be done with:
RewriteRule ^productfilter.php - [NC,L]
RewriteRule ^([^/]*)/?$ productfilter.php?category=$1 [NC,L]
The first RewriteRule just declines to rewrite when productfilter.php already starts the path.
http://www.domain.com/folder/file?x=1&y=2
Change to:
http://www.domain.com/folder/file/1/2/
http://www.domain.com/folder/?x=1
Change to:
http://www.domain.com/folder/1/
I tried:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^folder/(.*)/$ folder/index.php?x=$1 [L]
RewriteRule ^folder/file/(.*)/(.*)/$ folder/file.php?x=$1&y=$2 [L]
but that doesn't work, does anyone have any idea why?
when i take out the first rule, i can access the second one via:
http://www.domain.com/folder/1/2/
but not:
http://www.domain.com/folder/file/1/2/
god, i hope i am not confusing anyone who is reading this lol i hope it makes sense
Try
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^folder/file/(.*)/(.*)/ /folder/file.php?x=$1&y=$2 [L]
RewriteRule ^folder/(.*)/ /folder/index.php?x=$1 [L]
The order of the rules is important. You should always put the one with the most rules first as your way was getting to the first rule and then stopping because it was always true due to the (.*) which was capturing the file.
Did you try adding a / before the folder name?
RewriteRule ^folder/(.*)/$ /folder/index.php?x=$1 [L]
RewriteRule ^folder/file/(.*)/(.*)/$ /folder/file.php?x=$1&y=$2 [L]
i know this question has been asked/answered several times already, but i just cant seem to get past it. so, my apologies...
while in the site dev phase, i want the browsers address bar to display: domain.com/dev/item
i would like the RewriteRule to change it to: domain.com/dev/index.php?p=item
im using the .htaccess located in the public_html directory for this. the .htaccess within public_html/dev, which works fine, is configured to redirect everybody who is not using my ip to domain.com. my apache version is 2.2.15 and i've confirmed that i am able to redirect using .htaccess, but the top level .htacess simply doesnt work. here is the code im using:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^dev/(.*)$ dev/index.php?p=$1 [NC]
#variations tried: ^dev/(.*)+$, ^dev/(.*)+?$
the, including variations, results in a 404, /dev/item not found. removing the dev/ from ^dev/(.*)$ results in the correct url format, but the following server variables:
[REDIRECT_QUERY_STRING] => p=
[REDIRECT_URL] => /404.shtml
[QUERY_STRING] => p=
[REQUEST_URI] => /dev/item
my goal is to make a small change to support this type of rewrite for both the live site and the dev copy. but i just cant understand what im doing wrong. i really would appreciate any help.
You need to specify the / at the beginning of the rewrite paths.
Try this instead:
RewriteEngine on
RewriteBase /
# If request is for a file that does actually exist, don't rewrite.
RewriteCond %{REQUEST_FILENAME} !-f
# If request is for a directory that does actually exist, don't rewrite.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/dev/(.*)$ /dev/index.php?p=$1 [NC]