Mobile app version of vmapp.org
Login or Join
Lee4591628

: 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

@Lee4591628

Posted in: #Apache #Htaccess #Url #UrlRewriting

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]&section=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=&section=1 [R]
</Location>
</VirtualHost>

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Lee4591628

1 Comments

Sorted by latest first Latest Oldest Best

 

@Jessie594

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme