Forum Moderators: phranque
# Restructure URLS in the enquiry/ folder.
# folder/index.php?id=123 becomes folder/123/
RewriteRule ^enquiry/details/([0-9]+)/?$ enquiry/details/index.php?id=$1 [L]
RewriteRule ^enquiry/company/([0-9]+)/?$ enquiry/company/index.php?id=$1 [L]
RewriteRule ^enquiry/parts/([0-9]+)/?$ enquiry/parts/index.php?id=$1 [L]
RewriteRule ^enquiry/quotation/([0-9]+)/?$ enquiry/quotation/index.php?id=$1 [L]
RewriteRule ^enquiry/lost/([0-9]+)/?$ enquiry/lost/index.php?id=$1 [L]
RewriteRule ^enquiry/activity/([0-9]+)/?$ enquiry/activity/index.php?id=$1 [L] ...after form submissions, redirecting at the header level using location: is having none of it.
# folder/index.php?id=123 becomes folder/123/
RewriteRule ^enquiry/([a-z]+)/([0-9]+)/?$ /enquiry/$1/index.php?id=$2 [L]
SInce you are using a relative path substitution, this would be mandatory.
RewriteRule {all-old-URLs-here} /fixup.php [L] Maybe a bit of an aside, but worth clarification I think.... why are you "redirecting" at this stage? The form submission should go straight to the "pretty URL" (with trailing slash) and your mod_rewrite directives internally rewrite it.
And what does "is having none of it" mean? What actually happens? What URL are you (wanting to) going from / to?
You also state that you want a "trailing slash", but your RewriteRule pattern makes this optional. Do you have other "folders" that fit this pattern that you don't want rewritten?
Do you have a RewriteBase directive?
Does the preceding redirect happen strictly within php?
However, on the later, the page 404s, although, when I echo out the URL...
How is it optional?
You guys thinking that this is more of a PHP issue then?
You can presumably see the URL in the address bar that is triggering the 404?
The "?" after an element (a slash in this case) makes that element optional.
Maybe you should post you PHP redirection code. (Should a new thread be started in the PHP forum?)
Do you have any other directives in you .htaccess file? The redirection that lucy24 mentions, catching stray requests for the old URL, is handled by PHP as well?
RewriteEngine on
# Restructure the URLS in the following folders as they are all the same.
# /active-enquiries
# /all-enquiries
# /orders
# folder/?statusID=1&pageNo=2 becomes folder/1/2
RewriteRule ^active-enquiries/([0-9]+)/([0-9]+)/$ active-enquiries/index.php?statusID=$1&pageNo=$2 [L]
RewriteRule ^all-enquiries/([0-9]+)/([0-9]+)/$ all-enquiries/index.php?statusID=$1&pageNo=$2 [L]
RewriteRule ^orders/([0-9]+)/([0-9]+)/$ orders/index.php?statusID=$1&pageNo=$2 [L]
# Restructure URLS in the search/ folder.
RewriteRule ^search/([^/\.]+)/([0-9]+)/$ search/index.php?criteriaType=$1&pageNo=$2 [L]
# Restructure URLS in the enquiry/ folder.
# folder/index.php?id=123 becomes folder/123/
RewriteRule ^enquiry/details/([0-9]+)/?$ enquiry/details/index.php?id=$1 [L]
RewriteRule ^enquiry/company/([0-9]+)/?$ enquiry/company/index.php?id=$1 [L]
RewriteRule ^enquiry/parts/([0-9]+)/?$ enquiry/parts/index.php?id=$1 [L]
RewriteRule ^enquiry/quotation/([0-9]+)/?$ enquiry/quotation/index.php?id=$1 [L]
RewriteRule ^enquiry/lost/([0-9]+)/?$ enquiry/lost/index.php?id=$1 [L]
RewriteRule ^enquiry/activity/([0-9]+)/?$ enquiry/activity/index.php?id=$1 [L]
# Restructure URLS in the order/ folder.
# folder/index.php?id=123 becomes folder/123
RewriteRule ^order/details/([0-9]+)/?$ order/details/index.php?id=$1 [L]
RewriteRule ^order/company/([0-9]+)/?$ order/company/index.php?id=$1 [L]
RewriteRule ^order/parts/([0-9]+)/?$ order/parts/index.php?id=$1 [L]
RewriteRule ^order/documents/([0-9]+)/?$ order/documents/index.php?id=$1 [L]
RewriteRule ^order/invoice/([0-9]+)/?$ order/invoice/index.php?id=$1 [L]
RewriteRule ^order/order-confirmation/([0-9]+)/?$ order/order-confirmation/index.php?id=$1 [L]
RewriteRule ^order/delivery-note/([0-9]+)/?$ order/delivery-note/index.php?id=$1 [L]
RewriteRule ^order/purchase-order/([0-9]+)/([0-9]+)/?$ order/purchase-order/index.php?id=$1&poid=$2 [L]
RewriteRule ^order/split/([0-9]+)/?$ order/split/index.php?id=$1 [L]
# Restructure URLS in the administration/ folder.
RewriteRule ^administration/view/companies/([a-z0]+)/([0-9]+)/?$ administration/view/companies/index.php?letter=$1&id=$2 [L]
RewriteRule ^administration/view/manufacturers/([a-z0]+)/?$ administration/view/manufacturers/index.php?letter=$1 [L]
RewriteRule ^administration/view/suppliers/([a-z0]+)/?$ administration/view/suppliers/index.php?letter=$1 [L]
RewriteRule ^administration/view/parts/([0-9]+)/?$ administration/view/parts/index.php?limit=$1 [L]
RewriteRule ^administration/edit/company/([0-9]+)/?$ administration/edit/company/index.php?id=$1 [L]
RewriteRule ^administration/edit/branch/([0-9]+)/?$ administration/edit/branch/index.php?id=$1 [L]
RewriteRule ^administration/edit/contact/([0-9]+)/?$ administration/edit/contact/index.php?id=$1 [L]
RewriteRule ^administration/edit/part/([0-9]+)/?$ administration/edit/part/index.php?id=$1 [L]
RewriteRule ^administration/edit/supplier/([0-9]+)/?$ administration/edit/supplier/index.php?id=$1 [L]
RewriteRule ^administration/edit/manufacturer/([0-9]+)/?$ administration/edit/manufacturer/index.php?id=$1 [L]
RewriteRule ^administration/edit/user/([0-9]+)/?$ administration/edit/user/index.php?id=$1 [L]
RewriteRule ^administration/add/company/([0-9]+)/?$ administration/add/company/index.php?enquiryID=$1 [L]
RewriteRule ^administration/add/branch/([0-9]+)/?$ administration/add/branch/index.php?enquiryID=$1 [L]
RewriteRule ^administration/add/contact/([0-9]+)/?$ administration/add/contact/index.php?enquiryID=$1 [L]
# Restructure URLS in the knowledge-base/ folder.
RewriteRule ^knowledge-base/manufacturers/([a-z0]+)/([0-9]+)/?$ knowledge-base/manufacturers/index.php?letter=$1&id=$2 [L]
RewriteRule ^knowledge-base/suppliers/([a-z0]+)/([0-9]+)/?$ knowledge-base/suppliers/index.php?letter=$1&id=$2 [L]
RewriteRule ^knowledge-base/parts/([0-9]+)/?$ knowledge-base/parts/index.php?id=$1 [L]
# Restructure URLS in the reporting/ folder.
# folder/index.php?id=123 becomes folder/123
RewriteRule ^reporting/manufacturer-sales/breakdown/([0-9]+)/?$ reporting/manufacturer-sales/breakdown/index.php?manufacturerID=$1 [L]
# Remove the .php file extensions.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
# Stop people from seeing empty indexes.
Options -Indexes
# Only allow people onto ----- from within the main office.
AuthType Basic
AuthName "---- Requires Authentication"
AuthUserFile "/home/----/.htpasswds/public_html/----/passwd"
Require valid-user
Order deny,allow
Deny from all
Allow from xx.xx.xx.xx
Allow from xx.xx.xx.xx
Satisfy any Just to clarify, all you links and everything point to your new URL structure?
# Remove the .php file extensions.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
RewriteCond %{REQUEST_FILENAME}.php -f
# folder/?statusID=1&pageNo=2 becomes folder/1/2
RewriteRule ^active-enquiries/([0-9]+)/([0-9]+)/$ active-enquiries/index.php?statusID=$1&pageNo=$2 [L] I altered the 404 pages so there wasn't a redirection
RewriteRule ^/active-enquiries/([0-9]+)/([0-9]+)/$ active-enquiries/index.php?statusID=$1&pageNo=$2 [L] I had simply defined the 404 page in the .htaccess and by doing that, I couldn't see the incorrect URL in the browsers URL bar.
ErrorDocument 404 /missing.html
or ErrorDocument 404 /boilerplate/errordocs/missing.html
The path can be as long as you like, so long as it starts from the root. RewriteRule ^/ etcetera