What I'm trying to do is rewrite something like
http://www.example.com/folderA/aaa_bb_cc_ddd.php
to
http://www.example.com/folderB/aaa-bb.php
...and I'm have just an awful time figuring out how. Any help or a point in the right direction much appreciated.
This is really going to depend on what these many URL's look like, but for starters you can try this in your htaccess file in your document root:
RewriteEngine On
RewriteRule ^/?folderA/(.*)_cc_ddd\.php /folderB/$1.php [L]
The trick here is figuring out what (.*)_cc_ddd\.php needs to look like. It's entirely dependent on this list of many URL's that you need to alter.
Related
I have a client that has several files whose name is (for example) car.php, car_edit.php, car_review.php. These each come with query strings - so car.php?id=1234 or car_review.php?id=321. They would like the file names to be truck*.php rather than car*.php.
I'm hoping there's a way using htaccess to convert the url string to be truck*.php and use the current car*.php files. Also if possible I'd like to forward any page asking for car*.php to truck*.php.
I've done quite a bit of searching and haven't found an answer to doing this particular thing. Does anyone know how I might do this? Thanks.
You need rewrite rules. Try something like:
RewriteRule ^truck(.*).php$ /car.php?id=$1 [NC,L]
Note: This is untested, so may require tweaking.
RewriteEngine On
RewriteRule ^truck(.*)\.php$ /car$1.php [NC]
ought to do it. It should automatically transfer any URL query string like id=xxx over to the car*.php rewritten URL.
I am hoping to gain some help with a small trouble I am experiencing with configuring a .htaccess file. Basically, I want to retrieve 2 variables from a URL String.
For example:
If someone entered www.website.com.au/folder/category/item.php
I would like the .htaccess to retrieve the last two variables (being Category and Item) and parse them to my display-item.php page.
I have a rough idea of what I need to be doing (As per below) though with all the tutes I have been reading I am a little confused.
Any help would be greatly appreciated.
:) Paul
RewriteRule /folder/(.*)/(.*).php /folder/display-item.php?category=$1&item=$2 [L]
RewriteRule ^folder/(.*)/(.*).php /folder/display-item.php?category=$1&item=$2 [L]
Works a treat. Managed to get it working.
Basically I'm trying to figure out a way to make
http://www.mysite.com/check/google.com
show the contents of the page
http://www.mysite.com/check.php?site=test.com
and I want users to think that the actual URL is http://www.mysite.com/check/google.com instead of the long one.
But I need to do this in the friendliest way for Google so that they aren't looking at it as a redirect and it'll still rank well... Any help will be greatly appreciated if you can post some sample code... Thanks!
In the htaccess file in your document root, try adding:
RewriteEngine On
RewriteRule ^/?check/(.*)$ /check.php?site=$1 [L]
I am complete newbie in mod_rewrite, and I have been going through some sites reading how to handle this, all I could find was when the get variable was numbers and nothing about strings, and it turns out be over my head.
What I want to do is to rewrite display.php?name=blahblah123 to display/blahblah123
Together with the answer, I would love some sites where I can build some grasp over mod_rewrite myself.
Thanks
Edit:
With more searching, I came up with this
RewriteEngine On
RewriteBase /
RewriteRule ^display/([a-z]+)$ display.php?name=$1 [L]
The code above works, but for some reason, The page I get has no CSS. The CSS I see included shows Hostgator's 404 page CSS. But HTML looks fine, so does the content and everything else. Any idea?
Just to be clear, mod_rewrite is something that happens internally in apache. I find that sometimes people do not understand what it does and doesn't do. It will not take a url that you output and change it from
display.php?name=blahblah123
to
display/blahblah123
It will however, allow someone to make a request from your site for display/blahblah123 and convert that to display.php?name=blahblah123, so that your display.php script can operate on it.
Rewrite rules require an understanding of regular expressions. The better you understand regex the easier mod_rewrite will be for you.
As a beginner this article should help: http://www.sitepoint.com/guide-url-rewriting/
For your specific question, I'd probably use:
RewriteRule ^display/([a-zA-Z0-9]+)$ /display.php?name=$1
Try to put a "/" in front of the css file name.
<link rel=".." href="/style.css".
instead of
<link rel=".." href="style.css".
I've been messing with this for the last hour... visiting about 20 different Google tuts and I can't seem make my site rewrite the url in any way. I've even just tried changing .php to .html and I'm not having any luck.
Here's one of my many fails:
RewriteEngine on
RewriteRule viewItem(.*)\.htm$ /viewItem.php?id=$1
For this above one, I'm just trying to change my viewItem.php page to viewItem.html
My ultimate goal is to change hxxp://mydomain.com/viewItem.php?id=900 (as one example of an id) to hxxp://mydomain.com/details/
I'm then going to append the title on the end. I can do the append in php but being a newb to .htaccess, I'm apparently missing something glaringly obvious.
Any ideas?
Thanks much.
Did you miss the 'l' of 'html'?
RewriteRule viewItem(.*)\.html?$ /viewItem.php?id=$1