.htaccess

.htaccess regex rewrite rule

老子叫甜甜 提交于 2020-01-16 08:37:38
问题 I have the following regex: RewriteRule ^blogs/([^/]*)/([^/]*) blogs/index.php?blogger=$1&blog=$2 This works fine for the following cases: http://myurl.com/blogs/blog-name/blog-article/ http://myurl.com/blogs/blog-name/blog-article http://myurl.com/blogs/blog-name/ however it does not handle: http://myurl.com/blogs/blog-name How can I make the "/" separator optional in this regex? 回答1: I'd use: ^blogs/([^/]*)(/([^/]*))? And you'd just have to check and make sure that $2 is still correct (with

How to prevent access to a directory with htaccess?

旧街凉风 提交于 2020-01-16 07:56:17
问题 How do I prevent access to a given directory ? Here is the structure of my website : config.php .htaccess classes/ |----lib/ | |----... |----classes.php webroot/ |----index.php |----ctrl/ | |----... |----pages/ | |----... |----style/ |----... The DocumentRoot is webroot . I want to prohibit access to the following folders : ctrl , pages , style . But the files stored in these folders still have to be available to be included in the index.php file. In other words, there is an index.php file.

.htaccess / redirecting to https://www.example.com and virtual folder access

穿精又带淫゛_ 提交于 2020-01-16 05:28:07
问题 I have a domain example.com . I want users to be redirected to https://www.example.com whenever one of the following is typed: http://example.com http://www.example.com https://example.com I also need to redirect people accessing /asdf (or /asdf/ ) to /index.php?folder=asdf . I found some examples of code doing the first part, but there was always a debate about their effectiveness. Edit: (need some more help! :)) 回答1: Try these mod_rewrite rules: RewriteEngine on RewriteCond %{HTTP_HOST} !

How can I capture a fully qualified local URL path with mod rewrite?

半城伤御伤魂 提交于 2020-01-16 04:21:31
问题 How can I capture a fully qualified local URL path with mod rewrite? For instance, my project is located in http://{localhost}/projects/mywebsite/index.php I tried with this RewriteBase /projects/mywebsite/ but it does not work for ErrorDocument . my .htaccess, RewriteEngine on RewriteBase /projects/mywebsite/ ErrorDocument 404 /error.php I need to do ErrorDocument 404 /projects/mywebsite/error.php but it isn't dynamic. I have to change it in two places everytime for each project. Any ideas?

How to separate Microsoft Edge from Chrome in htaccess?

两盒软妹~` 提交于 2020-01-16 02:35:29
问题 I have this in my .htaccess file: RewriteEngine on RewriteCond %{HTTP_USER_AGENT} Chrome RewriteRule ^(.*)$ page.php [NC,L] Microsoft Edge browser thinks it is Chrome and goes to page.php. Is there any way to avoid Edge from using the Chrome command, so it would not go to page.php? I have googled so much and I haven't found anything how to direct Edge browser. Any help? Thanks!! 回答1: The Edge user agent has the word Edge in it, e.g. Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36

.htaccess redirect in wordpress

余生长醉 提交于 2020-01-16 02:08:18
问题 I would like users that go to the website 'http://kevingstongramado.p.ht/', to be redirected to 'http://kevingstongramado.p.ht/catalogo/'. Which is in fact a wordpress website. I´ve tried this: Redirect 301 /http://kevingstongramado.p.ht/ http://kevingstongramado.p.ht/catalogo/ Putting the .htaccess inside the root directory of the website. Not the root directory of the folder which contains the wordpress. Doesn´t work. "catalogo" is the folder which contains the 'index.php' that opens the

AngularJS page not working when refresh/share a link

心已入冬 提交于 2020-01-16 00:52:14
问题 I have a webpage and it's working just fine. The problem starts when i need to refresh the page or try to share a link with someone (or even open it in a new tab). When i try to do it, the page doesn't work. It loads only the header, footer, etc. But not the part inside my ng-view and also no css class, etc... Also, I'm using html5 mode in AngularJS with this code: $locationProvider.html5Mode({ enabled:true }); I tried to use a .htaccess to reload the page and it's working, but only for the

301 redirect to full path

百般思念 提交于 2020-01-16 00:35:29
问题 I have a lot incorrect back links, the links are pointing to: http://www.domain.com/tags/keyword while the correct path is http://www.domain.com/tags/keyword/ there are hundreds of those...how could i 301 redirect from the wrong links to the correct links? Thank you so much in advance 回答1: You can try this code: RewriteBase / RewriteRule ^tags/([^/]+)$ /tags/$1/ [L,R=301] RewriteBase / tells apache that your URI starts by a / . If your site was in a subfolder you should write RewriteBase

htaccess rewrite QueryString disappears in Apache 2.2 but works in 2.4

柔情痞子 提交于 2020-01-16 00:29:26
问题 Following is the rule: RewriteRule ^api/([\w-]+)/?$ api.php?method=$1 [QSA] On local Apache 2.4 server, it allows me to rewrite like: /api/create-account/?name=abcd to /api.php?method=create-account&name=abcd On production server, which is Apache 2.2, the request goes to api.php . But I find not query string parameter in my script. If I dump $_REQUEST , $_GET or $_POST , I only get empty array. What am I missing? 回答1: You need to turn off Multiviews: Options -Multiviews Multiviews is a mod

301 Redirects not working - Anyone know why?

*爱你&永不变心* 提交于 2020-01-15 23:07:07
问题 Can someone help? For some reason the 301 redirects are not working.... The rewrite conditons format my urls by removing the extensions, so not sure if I need to remove the extensions from the 301 statements or not. Options +FollowSymlinks RewriteEngine on RewriteCond %{HTTP_HOST} !^www\.beingchildren\.org$ [NC] RewriteRule ^(.*) http://www.beingchildren.org/$1 [L,R=301] RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.htm[\s?] [NC] RewriteRule ^ /%1 [R=301,L,NE] RewriteCond %{REQUEST_FILENAME