I have following urls generated in the html
http://www.xxx.com/page/26/website-design-services?ajax=true
configured .htaccess syntax to read the value of the page id is
# BEGIN Rewrite
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteBase /
RewriteRule ^page/([^/]+)/?(.*)$ page.php?section=$1 [QSA,L]
</IfModule>
# END Rewrite
When i call the php file to do the get like below it returns only ajax part in the GET array. see below in page.php
print_r($_GET);
$url = $_GET['section'];
output is
Array
(
[ajax] => true
)
any idea why it doesnt detect the other variables ?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^page/([^/]+)/ /page.php?section=$1 [NC,QSA,L]
Related
Friends i am php developer i did customize the url in example is
From : http://example.net/page.php?post_id=contact/
To : http://example.net/contact/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#RewriteBase use only home/phtml/www/ this kind of path
RewriteRule ^([a-zA-Z-/]+)$ page.php?post_id=$1 [QSA]
RewriteRule ^([a-zA-Z-/]+)/$ page.php?post_id=$1 [QSA]
</IfModule>
its working fine on above that htaccess code but it have some problem. What is i got "admin" folder for control panel purpose. In which how to redirect to http://example.net/admin/ correctly any option this in htaccess?
My error is: http://example.net/page.php?post_id=admin/
How to Solve this?
You can skip all directories from your rewrite rule. Use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z/-]+)/?$ page.php?post_id=$1 [L,QSA]
</IfModule>
Also you should keep unescaped hyphen at first or last place in a character class.
I combined 2 of your rules into one using optional trailing slash.
I need to redirect this:
http://www.mysite.com/pages/addtocart.php?id=XXXX
to this
https://www.mysite.com/checkout/cart/addsku?id=XXXX
Up to now, this is what I have:
RewriteRule ^/pages/addtocart.php?(.*)$ https://www.mysite.com/checkout/cart/addsku?$1 [R=301,L]
But it's not working.
Help?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^pages/addtocart\.php$ https://%{HTTP_HOST}/checkout/cart/addsku [L,R=302,NC]
PS: Query Parameter will automatically be carried over to new URL.
I need to remove directories from my local website url:
Current url : http://localhost/example/trunk/frontend/www
Needed url : http://localhost/example/frontend
I need to remove trunk and www folders from url without changing files (css, js, images, ...etc) paths.
Can anyone help me please?
Thanks
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 /
RewriteCond %{REQUEST_URI} !^/example/trunk/[^/]*/www [NC]
RewriteRule ^(example)/([^/]+)(/.*|)$ /$1/trunk/$2/www$3 [L,NC]
UPDATE:
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /example/
RewriteRule ^((?!trunk)[^/]+)(/.*|)$ trunk/$2/www$3 [L,NC]
On my Wordpress blog, I used to have a plugin that I no longer need. The plugin used to create a bunch of URLs that looked like this:
http://tambnguyen.com/manage-subscriptions?srp=532&sra=s
with the postID being 532. How do I redirect the query strings so that the above URL will redirected to:
http://tambnguyen.com/?p=532
I've tried a few method without any luck (there's an optional "/" after "manage-subscriptions"
<IfModule mod_rewrite.c>
RedirectMatch 301 ^/manage-subscriptions/?\?srp=(\d{1,5})(.*)$ http://tambnguyen.com/\?p=$1
</IfModule>
Please help. Thanks!
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 /
RewriteCond %{QUERY_STRING} ^srp=([^&]+) [NC]
RewriteRule ^manage-subscriptions/?$ /?p=%1 [L,R=301,NC]
I want to set up 301 redirects in my .htaccess file so URLs like
http://example.com/Foo
http://example.com/Foo/Bar
http://example.com/Foo/Bar/Blah
change to
http://example.com/products/foo
http://example.com/products/foo/bar
http://example.com/products/foo/bar/blah
There are a discrete number of "Foo" cases which I can target with RewriteRule ^Foo, but how to append the "products" part?
First add this line in <VirtualHost> section OR at the end of your httpd.conf file:
RewriteMap lc int:tolower
Then have these rules in .htaccess file:
RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteRule ^(Foo.*)$ /products/${lc:$1} [R=301,L]
R=301 for sending back 301 to browser
L for marking it last rule