: Apache URL Rewrite I'm trying and failing to get a URL rewrite working, firstly I'm doing it in the vhost declaration, is that right? What I'm trying to do is take any URL which has; view.php?id=[a
I'm trying and failing to get a URL rewrite working, firstly I'm doing it in the vhost declaration, is that right?
What I'm trying to do is take any URL which has;
view.php?id=[a 1 or multidigit number]
and rewrite it to
view.php?id=[number]§ion=1
Any help would be greatly appreciated, thanks for looking.
Okay, so I tried the suggestion below (thanks for that) and now have this in my vhost file but still no effect;
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin ########
DocumentRoot "########"
ServerName ########
ErrorLog "logs########.log
<Directory "########">
DirectoryIndex index.php index.html
AcceptPathInfo on
Order allow,deny
Allow from All
</Directory>
<Location />
RewriteEngine on
RewriteRule ^/view.php?id=([0-9]*)$ /view.php?id=§ion=1 [R]
</Location>
</VirtualHost>
More posts by @Lee4591628
1 Comments
Sorted by latest first Latest Oldest Best
What you are looking for is
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=(.+)
RewriteCond %{QUERY_STRING} !section=(.*)
RewriteRule ^/view.php$ /view.php?section=1 [R,QSA]
The first RewriteCond looks at the query string for an id. The second ensures there isn't already a section in the query string. [R,QSA] specifies that the redirect preserves existing query parameters.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.