regex


Rewrite sometext/ to sometext/sometext.php, forbid direct acces to sometext.php


I'am struggling with this for a couple of days.
Folder structure is:
index/files/pages/
In main folder (index) there is index.php - this is the only index.php file in whole page.
In files folder there are php files that are actually pages of the website.
In files folder there are couple of more folders (pages) that hold different pages - I just grouped the php fiels into folders to keep it tidy.
I am trying to achivie this.
When I enter url like index/files/pages/somename.php - I want to get 404 or whatever
When I enter url like index/files/somename - this gets rewritten to index/files/pages/somename.php, but the address looks clean.
Now whatever I do I can't get both rules to work, either one overwrites another or nothing works, I get 500 all the time.
Here is my rule that actually works:
RewriteRule ^([-0-9a-z]+)$ pages/$1.php - this is the scenario 2 and its ok.
Now when I add rule that handles direct access to php files, the previous rule is also affected and gets overwritten and everything throws 404, 500 etc. Flags like [L] etc don't have any effect, changing the order also does nothing.
Also I want to forbid direct access to index.php and redirect to index folder (and show clean url)
Here are some additional rules i tried, but no result. As I said earlier setting flags give no results.
RewriteCond %{REQUEST_URI} ^.*\/pages\/.*\.php$
RewriteRule ^(.+)$ [R=404,L]
RewriteRule ^([-0-9a-z]+)$ pages/$1.php
RewriteCond %{REQUEST_URI} ^(.+)\/index\.php
RewriteRule ^(.*)$ index/ [R=301,L]
RewriteCond %{REQUEST_URI} ^\/(.*)\.php
RewriteRule ^(.*)$ [R=404,L]
Thankx and regards
Try these rules:
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ index/ [L,R=302,NC,NE]
RewriteCond %{THE_REQUEST} \.php[\s?/] [NC]
RewriteRule ^ [F]
RewriteRule ^index/?$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]

Related Links

Regex Match for Valid Dates only
SoaupUI - Groovy replace All
how can I use a wildcard in restify routes
Regex - unknown place of character
Regex Replace 406 with 401
Replace string with another string based on backreference in bash
D: split string by comma, but not quoted string
move a pattern to the beginning of a line with sed
Need a modification in the regular expression
regular expression matching string in scala
Why is C#'s Regex.Matches() returning all matches in a single Match object?
From Matlab to R: Capture named fields with regular expressions to a dataframe
How can I find repeated words in a file using grep/egrep?
Pattern match with stored variable or regular expression in Bash
Regexp matching of “a*” in expect
grep to match a certain number sequence in a mix of text and numbers

Categories

HOME
apache-spark
opencv
ffmpeg
direction
design
jsonschema
chronicle
feed
splunk
python-2.5
smartsheet-c#-sdk-v2
accumulo
embed
slowcheetah
gyroscope
hp-alm
aspdotnetstorefront
urlrewriter.net
angular-services
f2py
parallax.js
reformatting
ocean
rdf4j
charts.js
cloudinary
html-select
jdk1.6
nav
sieve-of-eratosthenes
jackrabbit
jdom-2
msal
ecmascript-4
projection
monogame
karnaugh-map
sdcc
ewsjavaapi
openwebanalytics
vega-lite
dump
glfw
infiniband
android-identifiers
zbar
qtcpserver
django-errors
turnjs
rsh
insert-update
finalcut
pager
selenium2library
uploadify
isapi-rewrite
ota
flotr2
facebook-comments
wgs84
relaxng
sqlj
ane
oracle-bi
dbfit
par
xirr
wchar-t
nominatim
chunk-templates
pegkit
easynetq
excel-charts
nolio
misra
laravel-validation
datacontractserializer
disk-io
blazeds
re2c
bochs
external-dependencies
rcu
angularjs-module
timespan
domain-mapping
browserid
oncreate
mixing
jsr223
maven-bundle-plugin
cellid
bapi
settings.bundle
duplicate-data
combinators
winamp
custom-protocol
xtratreelist
help-authoring

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App