Jump to content

Rewrite Rule: Comma Separated


robj

Recommended Posts

I'm attempting to rewrite the following:

/test,name.php to /test

 

Here's the short story:

The files are being generated by a different department and are automatically placed on the server. There are 2 parts to the file name. The first is the type of data (which will always be different), and the second is the time/date/version/revision#/ stamp. The parts are currently being separated by a comma, but could be changed to a hyphen or period (underscore is cannot be used unless it's possible to define the last underscore as the separator).

 

I only want to display the first part of the file name, and preferably drop the .php extension. Example: http://www.MYURL.com/first_name,123456789.php would read http://www.MYURL.com/first_name

 

My current .htaccess file:

 

RewriteEngine On
RewriteBase /

# Externally redirect direct client requests for .php files to non-.php URLs
RewriteCond %{THE_REQUEST} ^GET\ /([^/]+/)*[^.]+\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php$ http://www.MYURL.com/$1 [R=301,L]
#
# Internally rewrite extensionless page URLs to PHP files
# if no extension or trailing slash on requested URL
RewriteCond %{REQUEST_URI} !(\.¦/$)
# and if filename exists when .php is appended
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.+) /$1.php [L]

 

I've tried quite a few attempts without getting close. I'm not as skilled with apache as I'd like (hence the notes) The above works perfect, but I need help with remove the comma and everything past it.

 

All help and ideas are appreciated. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/161541-rewrite-rule-comma-separated/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.