I have this url:
details
the url becomes in addressbar:
http://web228.sydney.webhoster.ag/soputnik/drive_to_london/?procid=12
but I want to process the logic in details.php.
How can I process the data in details.php in background and keep the first url in the address?
I tried this:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^drive_to_(.*)$ http://web228.sydney.webhoster.ag/soputnik/details.php [R=301,L]
but it is not working, error is: NOT FOUND
please help
Substitute your code with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^test/drive_to_(.*?)/?$ /test/details.php [L,NC]
If you don't want the URL to change, then it's not a redirect, just a rewrite.
Change:
RewriteRule ^/test/drive_to_(.*)$ /test/details.php [R=301,L]
To something like:
RewriteRule ^/test/drive_to_(.*)$ /test/details.php?city=$1 [L]
dont forget to pass any url params to details.php.
Rewriterule ^/drive_for_(.*)/\?(.*)$ http://domain.de/test/details.php/?$1 [R=301,L]
it seems relevant that you want to pass the city name as well, otherwise that context gets lost in the rewrite. If that is another url param you could pass it through to details.php as such
Rewriterule ^/drive_for_(.*)/\?(.*)$ http://domain.de/test/details.php/?$2&city=$1 [R=301,L]
Related
I don't have an idea how can I remove %2523 from URL made by GET in php. I want to redirect users to page without that. Sometimes it has # on string beggining, and that's why it generates that "%2523".
For example, want to redirect them from something like:
localhost/catalog/value/%2523string
to
localhost/catalog/value/string
My current .htaccess file:
Options -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/catalog/value\.php\?value=([^/]*)\s [NC]
RewriteRule ^ /catalog/value/%1? [R=301,L]
RewriteRule ^catalog/([^/]*)$ /value/value.php?color=$1 [L]
Hopefully you can help me with that, trying from yesterday and still didn't nothing works.
Finally i solved that by adding this at the .htaccess beggining:
RewriteRule ^([^%]*)\%23(.*)$ /catalog/value/$2 [R=301,L]
i have a url
http://domain.com/wallpaper-name-of-wallpaper-id.html
where wallpaper- is prefix of the url and name-of-wallpaper is title of the wallpaper while id is the actual id of the wallpaper. my current .hataccess file looks like.
RewriteRule ^wallpaper-([^/]*)\.html$ wallpaper.php?permalink=$1 [L]
but i want to change it to
http://domain.com/wallpaper/name-of-wallpaper-id.html
so user who will enter the old url will automatically sent to the new url with htaccess.
i have tried.
RewriteRule ^wallpaper-([^/]*)\.html$ wallpaper/wallpaper.php?permalink=$1 [R,L]
but don't seems to work for me. any idea or help?
Add a new redirect rule before existing rule:
Options -MultiViews
RewriteEngine On
RewriteRule ^(wallpaper)-([^.]+\.html)$ /$1/$2 [R=302,L,NC]
RewriteRule ^wallpaper/([^.]+)\.html$ wallpaper.php?permalink=$1 [L,NC,QSA]
I have a link like below:
In /country/search.php
<a href="<?php echo 'index.php?departments='.$value['department_id'].'&towns='.$value['town_id'].'&type='.$value['type_id'].'&id='.$value['id'] ?>">
When I use the below .htaccess code, it does nothing:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /country/index.php?departments=$1&towns=$2&type=$3&id=$4 [L]
It does in the tool:
http://example.com/0/0/4/122
... but when I click that link it shows old URL again.
What is the problem here?
I'm generating that .htaccess code using this tool: http://www.generateit.net/mod-rewrite/
Replace your code with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty URL
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(index\.php|)\?departments=([^\s&]*)&towns=([^\s&]*)&type=([^\s&]*)&id=([^\s&]*) [NC]
RewriteRule ^ %1/%2/%3/%4/%5? [R=301,L]
# internal forward from pretty URL to actual URL
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ /country/index.php?departments=$1&towns=$2&type=$3&id=$4 [L,QSA]
I think you misunderstood what the rewrite rules are trying to achieve in this context.
F.e. this rewrite rule
RewriteRule ^([^/]*)/([^/]*)$ /app.php?method=$1&arg=$2
Will ensure that a request to http://example.com/mymethod/myarg will be rewritten to
http://example.com/app.php?method=mymethod&arg=myarg
When you generate links from within your application you should know how you contstructed the rewrite rules and you have to build the link accordingly.
Original URL:
href="news.php?state="<?php echo $sql_res['state']?>"&country="<?php echo $sql_res['country']?>
Ideal URL:
/India/andhra%20Pradesh
And .htaccess code:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /news.php?country=$1&state=$2 [L]
I have the following format:
http://www.mydomain.com/view/product/ID/CAT/TITLE
ID and CAT are both numeric. So, some real examples:
http://www.mydomain.com/view/product/1/2/ipod
http://www.mydomain.com/view/product/3/4/40-inch-tv
etc
I want to know if I should try to use mod rewrite, and how, or if I should rather fix the PHP to handle the paths correctly. I want to map the above to something like:
http://www.mydomain.com/CATEGORY/SUB_CATEGORY/TITLE
Any ideas?
RewriteEngine on
RewriteBase /
RewriteRule ^([A-Za-z0-9]+)$ /$1/ [R]
RewriteRule ^([A-Za-z0-9]+)$ index.php?cat=$1
RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9]+)$ /$1/$2/ [R]
RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9]+)$ index.php?cat=$1&subcat=$2
RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9]+)/([A-Za-z0-9]+)$ /$1/$2/$3/ [R]
RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9]+)/([A-Za-z0-9]+)$ index.php?cat=$1&subcat=$2&title=$3
in php you can get the variables as you would normally do, also you will need a rule for all variables entered and/or only category or sub-category or you will end up with a 404 when someone tries to access those pages
I would say that your question is not totally clear to me. Going by your examples what do you want your target URL to become from http://www.mydomain.com/view/product/1/2/ipod.
Will it be: http://www.mydomain.com/2/1/ipod ?
If yes then enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^view/product/([0-9]+)/([0-9]+)/(.*)$ $2/$1/$3 [L,R,NC]
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]