the incoming URL
domain.com/12/3
should be re-written to
domain.com/?w=12&h=3
htaccess
RewriteEngine on
RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_-]+)$ index.php?w=$1&h=$2 [QSA]
the php
<?php
echo $_GET['h'];
?>
Result
404 page
I've tried using htaccess to change the result of the url and then retrieve the value from the URL, could someone help me out?
Maybe you need to escape - like:
RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_\-]+)$ index.php?w=$1&h=$2 [QSA]
PS. I hope the above URL /12/3 is just for example because your regex accepts only a-z
RewriteEngine On
RewriteRule ^[a-z]{2,2})/([a-zA-Z0-9_-]+)$ /index.php?w=$1&h=$2 [QSA]
Essentially, I'm pretty sure you need a / in front of index.php
I like to use this generator for my mod-rewrite rules.
http://www.generateit.net/mod-rewrite/
Try changing your rewriterule to the following:
RewriteEngine on
RewriteRule ^([a-z0-9]{2})/([a-zA-Z0-9_-]+)$ /index.php?w=$1&h=$2 [QSA]
Your example has two digits as the first parts of the path, which won't be matched by [a-z].
RewriteEngine On
RewriteRule ^(.*)/(.*)$ index.php?w=$1&h=$2 [QSA]
The above sorted it. Thanks for the replies
Related
I am trying to have it so foo.com/userinfo.php?user="username" will be re-written as foo.com/username. I have gotten this to work using RewriteRule ^([a-zA-Z0-9_-]+)$ userinfo.php?user=$1 in my htaccess. However, when a slash is added to the end of the username such as foo.com/username/ it just redirects it to foo.com/userinfo.php?user="username". While this does pull up the profile it doesn't look as well in the url bar. Thank you for any help!
Here is my .htaccess code now
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ userinfo.php?user=$1
You can use `/?' as the expression "the character / or nothing".
RewriteRule ^([a-zA-Z0-9_-]+)/?$ userinfo.php?user=$1
I try to rewrite my SEO URLs to some real GET requests, to handle in my PHP file.
I want to have these 2 cases to work:
mysite.com/company-profile -> index.php?action=company-profile
mysite.com/faq/howcanijoin -> index.php?action=faq&anchor=howcanijoin
I got the first case to work using the rule:
RewriteRule ^([A-Za-z0-9-]+)$ index.php?action=$1
For the second I tried also. I put this rule before the previous one:
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ index.php?action=$1&anchor=$2
But it's not working. Any suggestions? If I understand correctly inside each parenthesis goes variables $1, $2 etc?
Do this
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)/(.*)$ /index.php?action=$1&anchor=$2
This?
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ index.php?action=$1&anchor=$2 [QSA,L]
I want to change url for example http://www.mysite.com/cgshop/admin/index.php?route=common/home will become http://www.mysite.com/cgshop/cp/index.php?route=common/home.
Please help me to figure out this. Thanks in advance.
This should get you what you want.
It tests to see if the URI begins with /cgshop/admin/ and then captures the rest so it can redirect with a 301 to the new url. The QSA means it will also carry over the query string (everything after the ?).
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/cgshop/admin/.*$
RewriteRule ^cgshop/admin/(.*)$ /cgshop/cp/$1 [R=301,L,QSA]
RewriteEngine On
RewriteRule ^cgshop/cp/.*$ cgshop/admin/$1
Try this.......
I'm making a redirect script for my site, I use htaccess to rewrite the URL so it looks nicer.
eg. http://localhost/r/http://google.com is the URL, but when I printing the value it shows up like this http:/google.com.
One / is missing, how can I fix that?
Edit:
Rewrite rule:
RewriteRule ^r/(.*)/$ /system/offsite/redirect/index.php?url=$1 [L]
Thanks for any help :)
This behavior is due to Apache that removes empty path segments before mapping it. But you can access the original requested URI path via THE_REQUEST:
RewriteCond %{THE_REQUEST} ^GET\ /r/([^\ ]+)
RewriteRule ^r/ /system/offsite/redirect/index.php?url=%1 [L]
Use php urlencode function
EDIT:
//echo your url
echo 'http://localhost/r/'. urlencode('http://google.com');
and in your index.php file
//get your url
$url = urldecode($GET['url']);
I think REQUEST_URI variable will have correct text. Use it like this:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/r/(.*)$
RewriteRule ^r/ /system/offsite/redirect/index.php?url=%1 [L,QSA,NC]
What would be the apache rewrite url to extract the id number (434376) from this url?
http://stackoverflow.com/questions/434376/unique-url-slug
something like
RewriteEngine On
RewriteRule ^questions/([0-9]+)/?$([A-Za-z0-9-]+) post.php?post_id=$1 [NC,L]
...but it doesnt work on my site...any tips?
thanks
Tested:
RewriteRule ^questions/([0-9]+)/?.*$ rewrite.php?post_id=$1 [NC,L]
Well if the / is optional it probably should be:
RewriteRule ^questions/([0-9]+)/?([A-Za-z0-9-]+)?/?$ post.php?post_id=$1 [NC,L]
Let me know if it works..