How to keep original URL in addressbar after RewriteRule
This is a similar question on stackoverflow, but even with the answers there I can not solve this in my case.
I have this dynamic image:
https://www.glansbeton.be/teaser/glansbeton-400-400/StackOverflow_Belgium.jpg
If you open it, you can see that the htaccess is working and there is a redirect. I don't want the redirect. I want that the url is not to be changed.
##### https://www.glansbeton.be/teaser/glansbeton-400-400/koekoek_vlaanderen.jpg
RewriteRule ^teaser/glansbeton-400-400/([^\.]+)\.jpg$ https://www.glansbeton.be/teaser/glansbeton-400-400/teaser.php?keyword_city=$1 [L,NC]
Can someone give me a tip ?
Could you please try changing your rule to following once. Please make sure you clear your browser cache before testing your URLs.
RewriteRule ^teaser/glansbeton-400-400/([^.]+)\.jpg$ teaser/glansbeton-400-400/teaser.php?keyword_city=$1 [L,NC]
Related
I'm trying to modify the subdomain name in the URL to make it look nicer. My current URL look something like:
www.mystore.com/productInfo.php?cPath=11_11&productID=222
So, I want to make it nicer by Rewrite in .htaccess in main with this code:
RewriteEngine On
RewriteRule ^productInfo/([0-9_-]+)/([0-9_-]+) productInfo.php?cPath=$1&productID=$2 [NC,L]
When I run and test it on the URL by typing www.mystore.com/productInfo/11_11/222 in the URL it works well. However, when this page is redirected by a different page or is 'refreshed' with a self redirecting a href= link(in which the link is written in php by the previous programmer), the above old link is still visible in the URL instead of the new one.
I am still a beginner while I suspect that I might need to change something in the cPanel/Apache(I think) for this but currently, I am still do not have access to the cPanel control. Is there anything that I might have missed to write in the .htaccess file or I really do need the cPanel control or any other reasons?
Any help is appreciated. Sorry that I could not find similar questions on this.
You can use the following :
RewriteEngine On
RewriteBase /
#redirect /productInfo.php?cPath=foo&productID=bar to /productInfo/foo/bar
RewriteCond %{THE_REQUEST} /productInfo\.php\?cPath=([0-9_-]+)&productID=([0-9_-]) [NC]
RewriteRule ^ productInfo/%1/%2? [L,R=301]
#rewrite new URL to the old one
RewriteRule ^productInfo/([0-9_-]+)/([0-9_-]+) productInfo.php?cPath=$1&productID=$2 [NC,L]
I am currently developing a dashboard for my site but I have a problem with the configuration of my
.htaccess file. I will explain the problem:
I'm doing a redirect from
RewriteRule ^dashboard/(.*)$ guild.php?guild_id=$1
(.*) = Server ID.
But I would like to have this too:
RewriteRule ^dashboard/(.*)/features$ features.php?guild_id=$1
Except that it redirects me to the first file (guild.php and not features.php), I hope to have explained the problem well and that you could help me :) Thanks
With your attempted Rules, please try following htaccess rules. Make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
##Rules for uri which has feature in uri.
RewriteRule ^dashboard/([^/]*)/features/?$ features.php?guild_id=$1 [NC,L]
##Existing rule from OP, fixed NC,L flags in rules too.
RewriteRule ^dashboard/(.*)/?$ guild.php?guild_id=$1 [NC,L]
I'm trying to show the user the content of http://www.mysite.com/booking-request?code=### when visiting a url such as http://www.mysite.com/booking/ZHTU78
I'm sure this is simple, but I cannot understand why the following rule is not working for me. All I get is a 404 error.
RewriteRule ^booking\/([\w\d]+)$ /booking-request?code=$1 [L]
If I change the rule to
RewriteRule ^booking\/([\w\d]+)$ /booking-request?code=$1 [L,R=301]
It works, but with the obvious undesirable side effect of actually redirecting the browser to http://www.mysite.com/booking-request?code=###
I've also tried changing the url to redirect to to a single / to make sure it should be looking for an existing page, but no change.
It might be pertinent to mention this is on a drupal site and /booking-request is essentially a basic page, so drupal will have some functionality to redirect this page anyway, however I wouldn't have thought it should matter in this case.
edit
Here's a link to the whole htaccess file: http://pastebin.com/KPE6DK6N
Try change the rule to:
RewriteRule ^booking/([\w\d]+)$ /booking-request?code=$1 [L]
or
RewriteRule ^booking/([\w\d]+)$ http://www.mysite.com/booking-request?code=$1 [L]
It should work.
So I was able to use this code:
RewriteRule ^portfolio$ _pages/_portfolio/port.html [NC,L]
to rewrite my sites webpage from:
http://nkonecny.com/_pages/_portfolio/port.html
to
http://nkonecny.com/portfolio
My question is there a way to redirect people that use the old URL that shows the full file path automatically to the new cleaner file path without going into my html and editing each link?
In other words if they typing http://nkonecny.com/_pages/_portfolio/port.html it will automatically land them on http://nkonecny.com/portfolio ?
Read this tutorial
RewriteEngine on
RewriteRule ^_pages/_porfolio/port.html$ /portfolio [L,R=301]
RewriteRule ^portfolio$ _pages/_portfolio/port.html [NC,L]
You need to issue an HTTP redirect instead.
^/somepath(.*) /otherpath$1 [R]
I'm using a bunch of ReWrite rules in my .htaccess such as these
RewriteRule ^brochure/([^/]+)/?$ brochure.php?cat_path=$1
It's all working great thanks to answers I found by searching this site. But I've got a tiny little snag.
This rule works perfecty at the moment
RewriteRule ^([a-zA-Z0-9_-]+)?$ $1.php It catches all my urls like www.mysite.com/shane and requestes shane.php - So far so good, but when I call www.mysite.com I need it to request index.php
Which rule could I use for this?
Thanks people.
UPDATE - For the sake of future users needing similar help.
My rule of ^([a-zA-Z0-9_-]+)?$ $1.php was causing the problem I mentioned above. The question mark ? is not needed in this type of rule, when you remove the question mark the index.php file in the directory returns to being the default landing page. Thanks to Tomalak for the Help.
You don't need any rule for it. Just make sure that .php default index files for the directory and it'll happen automatically.
Update
I think that your rule
^([a-zA-Z0-9_-]+)?$ $1.php
should in fact be
^([a-zA-Z0-9_-]+)$ $1.php
so that it does not conflict with requests where the filename isn't given (which you want to direct to index.php).
I think this is what you're looking for,not sure thought:
RewriteRule ^/$ index.php
You can either do as Tomalak says, and ensure the DirectoryIndex is set to load index.php.
Or close to what James says,
RewriteRule ^/?$ index.php [L]