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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.