简体   繁体   中英

PHP Apache .htaccess URL Rewriting multiple variables

this is a long shot, not sure it's possible I've been trying a few different methods with URL rewrite in .htaccess. What i'm wanting is to keep the page name then replace the variables after with / the method i got working i had to create a folder called Issues then in there put a new .htaccess file and an index.php that should allow me the path i would like.

Path i'm looking for;

“Issues/Project-ID”

if not dash I'll have to follow url /or

"Issues/Project/ID"

The current setup I have is;

Issues.php?Project=name&ID=3

The current code I have been working with is this;

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^([^/]+)(/([^/]+))? Issues?Project=$1&ID=$2 [L]
</IfModule>

When I get it working with one variable it thinks the url is a folder and breaks my navigation, issues/ thinks it's outside root directory. Not sure if this is possible to run from the root directory.

Edit:

I have also tried a new way.

http://domain/Issues/Project/name/ID/2/

Options +FollowSymLinks
RewriteEngine on
RewriteRule Issues/Project/(.*)/ID/(.*)/ Issues.php?Project=$1&ID=$2
RewriteRule Issues/Project/(.*)/ID/(.*) Issues.php?Project=$1&ID=$2 

But $_GET is not getting the values of Project or ID

Don't bother with .htacces, redirect everything to one php file and in this file redirect with header (....); Easier and you do not need to convert later so many lines from .htaccess if you are moving to another server (eg windows).

RewriteEngine on
RewriteBase /

# Redirect to /
RewriteCond %{REQUEST_FILENAME} index.php
RewriteRule ^index.php$ http://%{HTTP_HOST}/ [R=301,L]

# Display already existing files and folders
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule (.*) $1 [NC,QSA,L]

# Rewrite all urls
RewriteRule ^(.*)/?$ router.php?url=$1 [NC,L,QSA]

# Favicon
RewriteRule ^favicon\.ico$ /favicon/favicon.ico [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM