简体   繁体   中英

htaccess file using the rewriterule to make the urls better

Hi I have a website eg website.co.uk

I would like a htaccess file using the rewriterule to make the urls better

Current URL

Website.co.uk?campaign=holiday&affiliate=1

the parameters (holiday & no 1) will change, depending on where the inbound link comes from

sometimes there will only be 1 parameter which would be the campaign like below

Website.co.uk/holiday

sometimes there will be 2 parameters

Website.co.uk/holiday/100

I have get variables in my php to get the variables on an index.php page

$campagin = $_GET['campaign'];
$affiliate = $_GET['affilaite'];

The first one has only 1 parameter Ie their might not be an affiliate Or the May be 2 parameters Ie a campaign and an affiliate

the page they are redirecting to is index.php

In my php it checks if the gets are set but just struggling with rewrite rule

I totally understand your concern, and there is this site, where you could randomly create your .htaccess file based on your requirements.

http://www.htaccessredirect.net/

Give it a try!

In the htaccess file in your document root:

RewriteEngine On

# for redirecting query string URLs to nicer path URLs
RewriteCond %{THE_REQUEST} \ /+(?:index\.php|)\?campaign=([^&]+)&affiliate=([0-9]+)
RewriteRule ^ /%1/%2? [L,R]
RewriteCond %{THE_REQUEST} \ /+(?:index\.php|)\?campaign=([^&]+)
RewriteRule ^ /%1? [L,R]

# internally rewrite path URLs back to query string
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)(?:/([0-9]+)|)$ /index.php?campaign=$1&affiliate=$2 [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